posted 15 years ago
The compound assignment operators have a very specific evaluation process:
- Evaluate the value of the variable in the LHS, and save that value.
- Evaluate the RHS expression.
- Perform the operation of the saved value of the LHS with the RHS value.
- Cast the result to the type of the LHS variable.
- Assign the result to the variable in the LHS.
Appart from this, in the RHS, you have ++a + a++. When you have a binary operator, the left operand is evaluated first, and then the right operand is evaluated. Sometimes it can make a difference on the final result (but this time it doesn't.)
All code in my posts, unless a source is explicitly mentioned, is my own.