What does the operation c=a+++b mean?(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 运算是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:c=a+++b 运算是什么意思?


- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 静态初始化顺序失败 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01