gpt4 book ai didi

c - x->a = x->b,++x++ ->b; 是什么意思?在给定的程序中做什么?

转载 作者:行者123 更新时间:2023-11-30 21:13:57 25 4
gpt4 key购买 nike

int main() 
{
struct data{
int a;
int b;
}y[4] = {1,10,3,30,2,20,4,40};

struct data *x = y;
int i;

for(i = 0; i < 4; i++)
{
x->a = x->b, ++x++ ->b;
printf("%d%d\t", y[i].a, y[i].b);
}


return 0;
}

这段代码是如何工作的?

最佳答案

声明

x->a = x->b, ++x++ ->b;  //note the comma operator after x->a = x->b

相当于

x->a = x->b;     // Assign member `a` to first member of element of array y 
++( (x++) ->b); // Fetch the member b of element of array y and then increment
// it by 1. Increment `x` by 1 after `b` is fetched.

关于c - x->a = x->b,++x++ ->b; 是什么意思?在给定的程序中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32157835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com