作业帮 > 综合 > 作业

#include struct ord { int x,y;} dt[2]={1,2,3,4}; main() {str

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/10 19:43:14
#include struct ord { int x,y;} dt[2]={1,2,3,4}; main() {struct ord *p=dt; printf("%d,",++
#include
struct ord
{
int x,y;} dt[2]={1,2,3,4};
main()
{struct ord *p=dt;
printf("%d,",++p->x);
printf("%d,",++p->y);
}
++p->x
++p->y
取值运算的优先级高于++
++p->x
++p->y
的含义等同于
++(p->x)
++(p->y)
前缀++,--与后缀++,--的区别在于
++i时,i=i+1,既i自增之后使用i
而i++表示,i=i,i=i+1既先使用i,然后i自增1
再问: 那结果为什么是2.3啊,p>x是怎么对应到函数中的啊 ?帮忙解释下这些语句吧 ,谢了
再答: dt[2]={1,2,3,4}表示dt[0]={1,2},dt[1]={3,4} p=dt表示p是dt数组的首地址,既此时p指向的数组是dt[0],p+1指向dt[1]; 因此p->x=1,p->y=2,所以输出结果为2,3。