*p++和(*p)++的区别
*和++是同优先级操作符,且都是从右至左结合的
∗ * ∗p++:取p所指单元的值,p指向下一单元,即p自加1,然后p指向下一个地址。和 (p++)意思一样
(*p)++:()的优先级比和++都高,所以++作用在()内的表达式p上,将p所指的数据的值加一
参考代码:
#include<stdio.h> void main(int argc,char*argv[])
{int a[4] = {3,7,9};int b[4] = {3,7,9};int c[4] = {3,7,9};int *p_a = a;int *p_b = b;int *p_c = c;int a1 = *p_a++;int b1 = *(p_b++);int c1 = (*p_c)++;printf("a1 = %d ,*p_a = %d \n",a1,*p_a);printf("b1 = %d ,*p_b = %d \n",b1,*p_b);printf("c1 = %d ,*p_c = %d \n",c1,*p_c);
}
结果:
a1 = 3 ,*p_a = 7
b1 = 3 ,*p_b = 7
c1 = 3 ,*p_c = 4
符合规则