p++ will return the value before it is incremented, and p will not be incremented until the end of the expression evaluation phase. Here *p++ can be regarded as a subexpression.
P++ If you are not familiar with it, use it sparingly. It won’t save much cost. It’s a simple matter of calculating first and then assigning a value, and first assigning a value and then calculating.
#include <stdio.h>
int main()
{
int a[]={1,2,3,4,5};
int *p;
p=a;
*(p+1)=10;
p++;
int i;
for (i=0; i<sizeof(a)/sizeof(int); i++) {
printf("a[%d]=%d\n",i,a[i]);
}
}
p++ and p are exactly the same, ++p is equal to (p+1), but no matter what, these two things exist in the subsequent code p=p+1. (If you still don’t understand, read the book yourself)
There is a simple method for you to understand: you can print p, p++ in sequence ((p++) still takes the scalar value p++, or here you can output &((p++)) ) and p. After looking at the results, you will understand that the memory address of *(p++) is still p, and then it becomes p+1
p++
++
followed byis equivalent to
is different from
++p
(p++)=10 (p++) returns the subscript of 0, so the result is like this. In fact, your sentence is equivalent to p++, and the result is the same
p++
will return the value before it is incremented, and p will not be incremented until the end of the expression evaluation phase. Here*p++
can be regarded as a subexpression.P++ If you are not familiar with it, use it sparingly. It won’t save much cost. It’s a simple matter of calculating first and then assigning a value, and first assigning a value and then calculating.
p++ and p are exactly the same, ++p is equal to (p+1), but no matter what, these two things exist in the subsequent code p=p+1. (If you still don’t understand, read the book yourself)
There is a simple method for you to understand: you can print p, p++ in sequence ((p++) still takes the scalar value p++, or here you can output &((p++)) ) and p. After looking at the results, you will understand that the memory address of *(p++) is still p, and then it becomes p+1
The difference between "prefix++" and "suffix++", classic test questions in c/c++