Crazy JAVA Post ++, java
I. x ++
Therefore, after the execution of x ++, the x value of the local variable area is directly 2;
Iinc: Specifies the int type variable to add the specified value. Note that it is a variable. In my explanation, iinc directly operates on local variables rather than the operation stack!★★★★
OUTPUT: 2
2. x = x ++ x
2. decomposition:X = x ++ x; a. 1 ++ assigns a value to x B. 1 + 2 of the local variable area to apply the 2 pressure stack of the local variable area.
C. x = 3 operation result assignment
2. Memory
OUTPUT: 3
Iii. x = x+ X ++
1. Pay attention to the differences between operations 2, 3, 4 and 2:Because x ++ is before the addition operation, iinc is used first, and then iload is used. Because x ++ is behind the addition operation, therefore, we can obtain the expected two operands for addition operations. Therefore, we first obtain two identical addition operations;
2. decomposition:X = x + x ++; a. 1 + 1 is pushed into the operation stack B. 1 + + local variable area to 2 c. x = 2 the operation stack is assigned a value to the local variable x
OUTPUT: 2
Iv. x = x ++
OUTPUT: 1