我们如何解释前pression的结果(++ x)+(++ X)+(++ x)的? [英] How do we explain the result of the expression (++x)+(++x)+(++x)?

查看:112
本文介绍了我们如何解释前pression的结果(++ x)+(++ X)+(++ x)的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x = 1;
std::cout << ((++x)+(++x)+(++x));

我希望可以将输出为 11 ,但它实际上是 12 。为什么呢?

I expect the output to be 11, but it's actually 12. Why?

推荐答案

我们期待通过的未定义行为的,而不是任何特定结果解释。由于前pression试图修改点¯x多次中间没有序列点它的behaviour是不确定的

We explain it by expecting undefined behaviour rather than any particular result. As the expression attempts to modify x multiple times without an intervening sequence point its behaviour is undefined.

这篇关于我们如何解释前pression的结果(++ x)+(++ X)+(++ x)的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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