struct m { int x; int *y; }*p; int a[4]={12,13,-40,100};struct m b[4]={10,&a[2],9,&a[3],8,&a[0],7,&a[7]};若p=b;printf("%d\n",++p->x);printf("%d\n",p->x);为什么两个输出的都是11?(VC++6.0)

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/14 03:49:32
struct m { int x; int *y; }*p; int a[4]={12,13,-40,100};struct m b[4]={10,&a[2],9,&a[3],8,&a[0],7,&a[7]};若p=b;printf(x);printf("%d\n",p->x);为什么两个输出的都是11?(VC++6.0)" />

struct m { int x; int *y; }*p; int a[4]={12,13,-40,100};struct m b[4]={10,&a[2],9,&a[3],8,&a[0],7,&a[7]};若p=b;printf("%d\n",++p->x);printf("%d\n",p->x);为什么两个输出的都是11?(VC++6.0)
struct m { int x; int *y; }*p; int a[4]={12,13,-40,100};
struct m b[4]={10,&a[2],9,&a[3],8,&a[0],7,&a[7]};
若p=b;
printf("%d\n",++p->x);
printf("%d\n",p->x);
为什么两个输出的都是11?(VC++6.0)

struct m { int x; int *y; }*p; int a[4]={12,13,-40,100};struct m b[4]={10,&a[2],9,&a[3],8,&a[0],7,&a[7]};若p=b;printf("%d\n",++p->x);printf("%d\n",p->x);为什么两个输出的都是11?(VC++6.0)
由于p=b,即p指向b所在内存
p->x就是b[0].x,所以等于10
printf("%d\n",++p->x); 中++在前,即先进行+1再返回值给printf,所以输出11
为什么后面的也是11呢,举个例子y=1,y++后y=2了,知道了吧,所以p->x值已经变为11了
所以第二个输出也是11