gpt4 book ai didi

c = a+(b++); printf ("output:c=%d\tb=%d\n",c,b); = 4,3

转载 作者:行者123 更新时间:2023-11-30 18:25:34 24 4
gpt4 key购买 nike

代码:

{
int a =2,b=2,c=0;
c = a+(b++);

printf("output:c=%d\tb=%d\n",c,b);
}

输出:

output: c=4      b=3

这里如何输出c = 4,我的理解是c=5,谁能解释一下吗?

最佳答案

因为++ii++之间是有区别的!

前缀/后缀

++i  // `Prefix` gets incremented `before` it get's used (e.g. in a operation)
i++ // `Postfix` gets incremented `after` it get's used (e.g. in a operation)

这就是为什么 c 是 4!

如果将 b++ 更改为 ++b,则 c 得到 5!

另请参阅:

What is the difference between prefix and postfix operators?

关于c = a+(b++); printf ("output:c=%d\tb=%d\n",c,b); = 4,3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27027603/

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