Answer E14

The first sum:  6.500000
The second sum: 4.500000
The third sum:  5.000000

The first expression is:

sum = a+b+2.0;

The assignment operator = and the variable sum are part of the expression. The assignment operator has low precedence, so it is performed last. It saves the value of the subexpression a+b+2.0 in the variable.

The entire assignment expression has a value and a type, which is the value and type stored in the variable.

The second expression is:

sum = a+b

This is a parameter to the printf and has the effect of saving the value of the subexpression a+b in sum. The entire assignment expression has a value and a type, the same as the value stored in the variable. That is the value that the printf uses.

printf("The second sum: %f\n", sum = a+b );   

The third expression is:

sum = sum+0.5

This adds 0.5 to the value in sum and puts the result back into sum.



Back to Puzzle Home