Okay. After theoretical analysis, let's take a look at why the results of the above two expressions are surprising.
For the first expression: A ^ = (B ^ = (a ^ = B )). First, the operator is decomposed into a = a ^ (B = B ^ (A = a ^ B), which makes it clearer.
1. The computer decomposition expression is a = a ^ temp1. Calculate a on the left. A is a variable, so a is replaced by 2. Next, we calculated the temp1 expression on the right and found that it was complicated and could not be directly replaced by a value. Therefore, we started to calculate the temp1 stack.
2. temp1 is B = B ^ (A = a ^ B ). On the left side of the calculation, B is a variable and can be directly assigned to 9. The expression on the right is replaced by temp2.
3. temp2 is a = a ^ B. On the left side of the calculation, A is a variable, and 2 is replaced; B is also a variable, and 9 is replaced. And calculate temp2 = 2 ^ 9 = 11.
4. regression calculation Temp 1 = 9 ^ temp2 = 9 ^ 11 = 2, that is, B = 2.
5. regression calculation A = 2 ^ temp1 = 2 ^ 2 = 0. That is, a = 0.
OK. The result of 0 and 2 is displayed.
For the second expression: J = (I ++) + (I ++ );.
1. Calculate the expression on the left, I ++. Because it is a suffix, the (I ++) expression returns I. At this time, I = 0, meaning 0 is returned.
2. Execute the ++ operator. 0 ++ is 1, So I = 1;
3. Calculate the expression (I ++) On the right, which is also a suffix. Therefore, I is returned. At this time, I = 1, which means 1 is returned;
4. Execute the ++ operator. 1 ++ is 2, so I = 2;
5 is assigned to J. J = 0 + 1 = 1.