How do we explain the result of the [removed]++x)+(++x)+(++x)?

后端 未结 5 1667
滥情空心
滥情空心 2020-11-28 13:05
x = 1;
std::cout << ((++x)+(++x)+(++x));

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

5条回答
  •  孤独总比滥情好
    2020-11-28 13:35

    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.

提交回复
热议问题