c=a+++b 运算是什么意思? [英] What does the operation c=a+++b mean?

查看:21
本文介绍了c=a+++b 运算是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码让我很困惑

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 运算是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆