Is (++i)++ undefined behavior?

眉间皱痕 提交于 2019-12-04 06:24:00

My gut feeling says this is undefined in C++03 and well-defined in C++0x.

Yes you are right. The behaviour is undefined in C++03 because you are trying to modify i more than once between two sequence points.

The behaviour is well defined in C++0x because (++i)++ is equivalent to (i += 1)++. The side effects of the += operator are sequenced relative to ++ (post increment) and so the behaviour is well defined.

Sunil

This is an undefined behaviour since i is being modified more than once between two sequence points.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!