Why is this Undefined Behavior?

前端 未结 3 824
我在风中等你
我在风中等你 2021-01-13 10:29

Why does the following given expression invoke undefined behavior?

int i = 5;
i = (i,i++,i) + 1 

My question is influenced by Als\' questio

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 11:12

    It is undefined in C++ to assign an incremented value to itself:

    i = i++
    

    What should i be after this? Should it be the previous value or one plus the previous value? The order of execution is left to the compiler, so different platforms will have different results.

提交回复
热议问题