I ++ has always been afraid of being like a wolf, because it has never dared to face the side effects of it. Today I have carefully understood the mechanism as follows.
When running to I ++, the execution sequence is as follows:
1 ~ I was launched and obtained by users.
2 ~ I execution ++.
3 ~ The user starts to use the introduced I value.
The three steps also explain why I = I ++; The I value obtained by such a statement remains unchanged.
Similarly, the execution sequence of ++ I is as follows:
1 ~ I execution ++.
2 ~ I was launched and obtained by users.
3 ~ The user starts to use the introduced I value.
2012-09
The above is an article from a year ago and will be commented on later this year.
Int I = 0;
I = I ++;
I still stick to pragmatism for such a problem, so I tried it with Visual Studio, QT creator, and eclipse and found that the answer to the C ++ compiler is 1, the Java compiler is 0.
This is not a problem in the C ++ specification, that is, different compilers have different implementations.
Let's take a look at the post ++ operator's statement: "post-auto-increment operations", which is not clearly defined afterwards.
Before getting the right operand? Or after obtaining the right operand?
Not explicitly stated.
Of course, for the absolute, the answer to this question is indeed 0 in the universal sense, because I ++ returns the value before the ++ operation.
However, compiler writers may not be absolute.
We recommend that you write programs less dependent on this undefined situation.