++ I: Before using I, perform the auto-increment action;
I ++. After I is used, the auto-increment action is performed.
For example: (1) I = 1, j = I ++; // J = I ++, that is, J references the I value first, and then I completes the ++ action.
Printf ("% d, % d \ n", I, j); // The result is I = 2, j = 1
(2) I = 1, j = ++ I; // J = ++ I, that is, I first complete the ++ action, and then J references
Printf ("% d, % d \ n", I, j); // The result is I = 2, j = 2
(3) int I = 1, j = 2;
Int K = I ++ J; // K = (I ++) + J. The value of I ++ is 1, k = 1 + 2 = 3.
Cout <k <Endl; // K = 3
(4) int I = 3, j = 4;
I? I ++: ++ J; // use of conditional operators. If? If it was previously an operational expression, it would be true or false ;? If it is only a number, check whether it is not 0.
Printf ("% d/N", I, j); // I = 3 Non-0, the first expression I ++, ++ J is not executed, so the result is: 4, 4.
(5) Which of the following is the most efficient? x = x + 1, x + = 1, x ++? Why?
X = x + 1 minimum // execution process: read the right X address, x + 1, read the left X address, and pass the right value to the left X (the compiler does not think that the left and right X addresses are the same ).
X + = 1 second // Execution Process: Read the address of the right x, x + 1, and pass the obtained value to X (the address of X has been read) Three Steps
X ++ maximum // Execution Process: Read the X address and perform the X ++ operation in two steps.
(6)
# Include <stdio. h>
# Define product (x) (x * X) // macro defines the macro name as product (x), and the string is (x * X) X as the parameter, that is, the macro operation expression.
Int main ()
{
Int I = 3, J, K;
J = product (I ++); // J = (I ++) * (I ++) Because I ++ is referenced first, j = 9. I ++ twice, so the last I = 5,
K = product (++ I); // K = (++ I) * (++ I), because ++ I is auto-incremented twice and then referenced, so k = 7*7 = 49
Printf ("J = % d, K = % d", j, k); // J = 9, K = 49
Return 0;
}
Reference: http://blog.csdn.net/lutongbin/article/details/6083810