1. What is the output of the following code?
Int main ()
{
Int A [2] = {0, 0 };
Int * P =;
* (P ++) = 1;
Cout <A [0] <A [1] <Endl;
System ("pause ");
}
The result is 10, that is, a [0] = 1, a [1] = 0. Although there are Parentheses, p is not first Auto-incrementing. In fact, the auto-incrementing step occurs after the expression where the symbol is located ends. That is, * (p ++) = 1; equivalent to * p = 1; p ++;
2. What is the output of the following code?
Int main ()
{
Int A = 1;
Cout <(A ++) * (a ++) <Endl;
A = 1;
Cout <(++ A) * (++ A) <Endl;
System ("pause ");
}
The former outputs 1, and the latter outputs 180.
For post-addition, (A ++) * (A ++) is equivalent to A * A; A ++; A ++; that is, 1*1*1*1 = 1.
For the prefix addition, if you take it for granted, add the prefix four times before multiplication. The result is 5*5*5*5 = 625, and the result is 180. In fact, the add-on is more complex:
· First, computing (++ A) * (++ A) is equivalent to ++ A; A *;
· Then, multiply by the third factor, which is equivalent to ++ A; the existing result is *;
· Finally, multiply by the fourth factor, which is equivalent to ++ A; the existing result is *.
· 3*3*4*5 = 180.
3. Summary
For the add-on operation, the add-on operation is performed after the expression.
For the add-on operation, the add-on operation is performed before the expression, but the combination sequence inside the expression is considered, that is, the subexpression problem is considered for gradual addition.
4. Questions
Although it has been verified by the program, some people on the Internet say this, but the combination of "Add before" and "Add after" inside the expression is different, it is not clear why subexpressions are considered for "Add after" and not for "Add before.
The compilation tool dev c ++ has also been verified in the reference articles for VC6.0. It cannot be guaranteed for other compilers.
5. Reference
C language auto-incrementing operator in-depth analysis http://www.bhcode.net/article/20110226/15159.html