Recall the difference between pre-increment and post-incprement:
Pre-increment adds 1 to the value of the variable and returns a reference to it. Thus, ++i = x; is valid.
Post-increment first makes a copy of the original variable, increments the original, and returns the temporary copy. Thus, i++ = x; is not valid. The net effect is that it returns a temporary copy of the old value.
Pre- and Post-increment both happen before addition (
http://www.cplusplus.com/doc/tutorial/operators/ ) and post-increment occurs before pre-increment. Post-increments are left to right order and pre-increment are right to left order.
So, b starts at 5.
x=b++ + ++b + b++;
First, we do post increment left to right which returns the old value:
x=5 + ++b + 6;
b is currently at 7.
Then, we do pre-increment from right to left which returns the variable itself:
x=5 + 8 + 6;
b is currently 8.
x now equals 19.
y=b++ + b++ + ++b;
Post-increment left to right:
y=8 + 9 + ++b;
b is currently at 10.
Pre-increment right to left:
y=8 + 9 + 11;
b is currently 11.
y now equals 28.
z=++b + b++ + b++;
Post-increment left to right:
z=++b + 11 + 12;
b is currently at 13.
Pre-increment right to left:
z=14 + 11 + 12;
b is currently 14.
z now equals 37
Thus, the C++ standard compliant results are
19 28 37 14.