Example:
The code is as follows: |
Copy code |
# Include <stdio. h> Int data [2] = {100,200 }; Int moredata [2] ={ 300,400 }; Int main (void) { Int * p1, * p2, * p3; P1 = p2 = data; P3 = moredata; Printf ("* p1 = % d, * p2 = % d, * p3 = % dn", * p1, * p2, * p3 ); Printf ("* p1 ++ = % d, * ++ p2 = % d, (* p3) ++ = % dn", * p1 ++, * ++ p2, (* p3) ++ ); Printf ("* p1 = % d, * p2 = % d, * p3 = % dn", * p1, * p2, * p3 ); Return 0; } His output is: * P1 = 100, * p2 = 100, * p3 = 300 * P1 ++ = 100, * ++ p2 = 200, (* p3) ++ = 300 * P1 = 200, * p2 = 200, * p3 = 301 |
The rest are clear, so what is vague is the difference between * p ++ and * ++ p. Let's recall what I ++ and I do, one is to use first, then calculate, the other is to calculate first, and then use (see the question below to understand I ++ and ++ I). According to the priority, * is the same as ++, they perform operations from the right to the left, so we should first consider the situation of ++, so the former * p1 once (used), in the calculation (p1 ++ is not * p1 ++ ), the latter is different.
Of course, it is better to have parentheses, which is clearer * (start ++)