指针符号的优先级
#include <stdio.h> #include <stdlib.h> struct i2c_dev { int fd; int addr; }; static struct i2c_dev i2c[3]; static struct i2c_dev* pi2c; int main() { pi2c = &i2c[1]; i2c[1].fd = 0x02; printf("i2c_dev fd is %d\n",++pi2c->fd); // 3 printf("i2c_dev fd is %d\n",pi2c++->fd); // 3 return 0; }
#include <stdio.h> #include <stdlib.h> struct stu { int x; int *y; }; struct stu*p; int dt[4] = {10,20,30,40}; struct stu a[4] = {50,&dt[0],60,&dt[1],70,&dt[2],80,&dt[3]}; int main() { p = a; printf("%d,",++p->x); // 51 printf("%d,",(++p)->x); // 60 printf("%d\n",++(*p->y)); // 21 // -> 这个优先级 比较高 return 0; }
一勤天下无难事。