C/C++ Math Order of Operation

后端 未结 5 1478
一生所求
一生所求 2020-12-11 19:10

So I know that C++ has an Operator Precedence and that

int x = ++i + i++;

is undefined because pre++ and post++ are at the same level and t

5条回答
  •  既然无缘
    2020-12-11 19:44

    The first code snippet is undefined behaviour because variable i is being modified multiple times inbetween sequence points.

    The second code snippet is defined behaviour and is equivalent to:

    int i = (1 / 2) / 3;
    

    as operator / has left-to-right associativity.

提交回复
热议问题