C/C++ Math Order of Operation

后端 未结 5 1463
一生所求
一生所求 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:34

    In your example the compiler is free to evaluate "1" "2" and "3" in any order it likes, and then apply the divisions left to right.

    It's the same for the i++ + i++ example. It can evaluate the i++'s in any order and that's where the problem lies.

    It's not that the function's precedence isn't defined, it's that the order of evaluation of its arguments is.

提交回复
热议问题