help!!

Question:

State the values of each of these int variables after the calculation is performed. Assumed that, when each statement begins executing, all variables have the integer value 5.

a) product *= x++;

b) quotient /= ++x;

What is the answer for a and b?
Thanks guys :)
you know, it would be extremely easy to just type this into a program and get the result that way.
*= and /= operators do * and / operations with left and right operands and save result in the left operand.
++x and x++ are very differend. ++x means first increment x then use it in this calculation, x++ means use x in this calculation then increment it.
int product = 5;
int x = 5;

product *= x++;
product = product * x++;
product = 5 * 5++;
product = 5*5 = 25; x = 6;


int quotient = 5;
int x = 5;
quotient /= ++x;
quotient = quotient / ++x;
quotient = 5 / ++5;
x = 6; quotient = 5/6 = 1;
Stewbond fails for supplying full homework solutions.

Especially when the homework is as simple as printing the output of a single assignment.
Last edited on
Topic archived. No new replies allowed.