Distinguish *P++, *(p++), *(++p), ++(*p), *(P--), *(--P)

1,*p++

Since ++ and * have the same priority and the combination direction is from right to left, it is equivalent to *(p++). First quote the value of p, implement the operation of *p, and then increase p by 1. ======Note===== Why is *p executed first and then *p++, shouldn't it be p++ in parentheses and then *p? In fact, the order of operations before and after ++ is forgotten here, and *p++ is used to illustrate the problem. In fact, p++ is executed first, and then *p. But the execution of p++ means (note) use p first, then p++, so this is a combination of first executing *p, that is, quoting first, and then executing p++ auto-increment!

2. *(p++) and *(++P)

The former is to first take the value of *p, and then increase p by 1. The latter is to increase p by 1, and then take *p. If the initial value of p is &a[0], output *(P++) to get the value of a[0]. Output * (++p), get the value of a[1]

3,++(*P)

Indicates that the element pointed to by p is plus 1, if p = a, then ++(*p) is equivalent to ++a[0], if the value of a[0] is 3, then after executing ++(*p) a The value of [0] is 4. Note that the value of the element a[0] is increased by 1, not the value of the pointer p.

4. *(P--) and *(--P)

*(P--): Perform "*" operation on p first, and then decrement p.
*(--P): Decrease p first, and then perform "*" operation.


1,*p++

Since ++ and * have the same priority and the combination direction is from right to left, it is equivalent to *(p++). First quote the value of p, implement the operation of *p, and then increase p by 1. ======Note===== Why is *p executed first and then *p++, shouldn't it be p++ in parentheses and then *p? In fact, the order of operations before and after ++ is forgotten here, and *p++ is used to illustrate the problem. In fact, p++ is executed first, and then *p. But the execution of p++ means (note) use p first, then p++, so this is a combination of first executing *p, that is, quoting first, and then executing p++ auto-increment!

2. *(p++) and *(++P)

The former is to first take the value of *p, and then increase p by 1. The latter is to increase p by 1, and then take *p. If the initial value of p is &a[0], output *(P++) to get the value of a[0]. Output * (++p), get the value of a[1]

3,++(*P)

Indicates that the element pointed to by p is plus 1, if p = a, then ++(*p) is equivalent to ++a[0], if the value of a[0] is 3, then after executing ++(*p) a The value of [0] is 4. Note that the value of the element a[0] is increased by 1, not the value of the pointer p.

4. *(P--) and *(--P)

*(P--): Perform "*" operation on p first, and then decrement p.
*(--P): Decrease p first, and then perform "*" operation.


Guess you like

Origin blog.csdn.net/publicstaticfinal/article/details/90005142