C language auto-incrementing operator Summary
[Example]
Int I = 5, j = 5, p, q;
P = (I ++) + (I ++ );
Q = (++ j) + (++ j );
Printf ("% d, % d \ n", I, j, p, q );
I = 5;
J = 5;
P = (I ++) + (I ++ );
Q = (++ j) + (++ j );
Printf ("% d, % d \ n", I, j, p, q );
I = 5;
J = 5;
P = (I ++) + (I ++ );
Q = (++ j) + (++ j );
Printf ("% d, % d \ n", I, j, p, q );
I = 5;
J = 5;
P = (I ++) + (I ++ );
Q = (++ j) + (++ j );
Printf ("% d, % d \ n", I, j, p, q );
[Description]
Compile and run in VC6.0.
The running result of this program is
7, 7, 10, 14
8, 8, 15, 22
9, 9, 15, 22
10, 10, 25, 41
It can be seen that after the complete subcomputation OF a ++, several ++ operations are counted, and then a few more are added to. While
++ A: When there are less than two operations, calculate the number of ++ operations first, then add them, and then assign values. If there are more than two, the third start is step-by-step. The first two are completed, and the third end uses the obtained value. Therefore, q = (++ j) + (++ j); (j = 5) q is equal to 7 + 7 + 8 = 22.
To sum up, in the vc environment: ++ I first increases the value of I twice and then assigns a value! I ++ first assigns a value and then increases the value of I twice!
Note]
The object of the auto-incrementing auto-subtraction operator is a variable, not a constant or expression. For example, ++ I ++ j is invalid. This is because the C-language compiler makes up as many characters as possible as an operator or identifier during program compilation from left to right, therefore, ++ I ++ j is equivalent to ++ (I ++) + j, the 1st "++" objects are used to define the expression "I ++", which is not allowed.
Author "record bit by bit"