Why does postfix operator++ have higher precedence than prefix operator++?

前端 未结 3 1857
感动是毒
感动是毒 2021-01-04 09:42

Defined this way, we can do neither ++x++ nor ++x--. But on the other hand, both (++x)++ and (++x)-- are useful expressio

3条回答
  •  走了就别回头了
    2021-01-04 10:08

    Both (++x)++ and (++x)-- invoke undefined behaviour [assuming x to be a primitive type]. For user defined type the scenario would be different. However it is not generally recommended to use such confusing expressions in your code.

    As far as the precendence is concerned this answer explains why post increment has higher precedence than pre increment.

提交回复
热议问题