On the code:
public static void main(String[] args) {
int j = 0;
for (int i = 0; i < 100; i++) {
j = j++;
System.out.println(j);
}
System.out.println(j);
}
If you follow CPP's understanding, the result should be 100. Java, however, is 0. Because Java is executing on the self-decrement operation, Java is executed by assigning temporary variables.
For example: j = j + +, this is done: int temp = J; j = j + 1;j = temp; Post operation is replaced after + 1.
If it is J = ++j, this is done: j = j+1; int temp = J;J = temp; the predecessor operator is replaced by the first +1.
Well, it's a rare idea to understand the intermediate cache variable substitution: int k = 0;k = ++k + k++ + k++ + k++;System. Out. println (k);
How much is the answer? O (∩_∩) o7! The detailed execution process is as follows: ++k:k = K+1;TEMP1 = k --1
k++: Temp2 = k --1K = k+1;
K++:temp3 = k --2K = k+1;
K++:temp4 = k --3K=k+1
So:k = Temp1 + temp2 + Temp3 +temp4 = 7 statements placed in CPP are also 7.
PS, why this kind of dark topic feeling. :: >_<:: Or Python good, direct to ++--unsupport
From for notes (Wiz)
The mechanism of intermediate cache variables in Java