DiGuru said:
If true, what's the difference between pre and postincrement?
Well, the timing of when pre-increment and post-increment are executed isn't defined, so post increment can indeed be evaluated before the rest of the statement is executed (this probably isn't done for built-in types, for performance reasons, but may be for other types).
Here's an example of how these are overloaded:
http://www.cs.bu.edu/teaching/cpp/overload/incr-op.html
Notice that the pre- and post- increment operators are completely different function calls, with the return value set by the function, such that one might expect the following:
x = 1;
x += x++ + x++;
...to result in x = 6. That is, if the evaluation order is left to right, we can incrementally replace the functions by their return values, recording the value of x at each step:
x += x++ + x++; (x = 1)
x += 1 + x++; (x = 2)
x += 1 + 2; (x = 3)
(x = 6)
Instead, if the compiler doesn't evaluate the ++'s until after the statement, for the purpose of performance (which seems likely), then the result would be x = 5.
edit:
Yes, if I use the integer type for the above statement, the resultant value for x is 5. If I make a little integer container class and overload the above operators, the return value is 6.