1. 程式人生 > >指標的偏移與自增自減

指標的偏移與自增自減

#include <stdlib.h>
#include <stdio.h>
int main(){
int a[3]={2,7,14};
int *p;
int i;
p=a;
i=*p++;//p指向a[1]
printf("a[0]=%2di=%2dp=%2d\n",a[0],i,*p);//2,2,8
i=p[0]++;
printf("a[0]=%2di=%2dp=%2d\n",a[0],i,*p);//2,7,8
i=++*p;
printf("a[0]=%2di=%2dp=%2d\n",a[0],i,*p);//2,9,9
i=++p[0];
printf("a[0]=%2di=%2dp=%2d\n",a[0],i,*p);//2,10,10
system ("pause");
return 0;
}