Today, someone posted a problem in the Forum:
Int I = 1, d; d = (++ I) + (++ I); printf ("% d \ n", d );
What is the output result above?
If not. You can first think about the result? Then perform programming verification again. If you cannot figure it out, check the cause again.
In fact, this is related to the processing of the compiler. The output result here is actually 10. What I originally thought was 9.
Cause analysis:
+ Operators are combined from left to right. Therefore, (++ I) + (++ I) calculates the first two ++ I (the size of I has changed to 3) then calculate the first + operation, so the result of the preceding (++ I) + (++ I) is 6 (do not forget that the result of ++ I is the left value I, instead of the right value 3 ). Then, calculate the last ++ I. Since I is 3 before it, the value of I after this operation is 4, so the final result is 6 + 4 = 10.
This question is an understanding of the operator's priority order and return value.
However, if such code is written in actual programming, it will be scolded by others.