下面的代码让我很困惑
int a=2,b=5,c;
c=a+++b;
printf("%d,%d,%d",a,b,c);
我预计输出为 3,5,8,主要是因为 a++ 表示 2 +1 等于 3,而 3 + 5 等于 8,所以我预计为 3,5,8.结果是3,5,7.有人可以解释为什么会这样吗?
I expected the output to be 3,5,8, mainly because a++ means 2 +1 which equals 3, and 3 + 5 equals 8, so I expected 3,5,8. It turns out that the result is 3,5,7. Can someone explain why this is the case?
被解析为c = a++ + b
,而a++
表示后增,即后增取a
的值来计算a + b == 2 + 5
.
It's parsed as c = a++ + b
, and a++
means post-increment, i.e. increment after taking the value of a
to compute a + b == 2 + 5
.
请永远写这样的代码.
这篇关于c=a+++b 运算是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!