Operator Precedence vs Order of Evaluation

后端 未结 6 1488
悲&欢浪女
悲&欢浪女 2020-11-22 06:38

The terms \'operator precedence\' and \'order of evaluation\' are very commonly used terms in programming and extremely important for a programmer to know. And, as far as I

6条回答
  •  被撕碎了的回忆
    2020-11-22 07:13

    I think it's only the

    a++ + ++a
    

    epxression problematic, because

    a = a++ + ++a;
    

    fits first in 3. but then in the 6. rule: complete evaluation before assignment.

    So,

    a++ + ++a
    

    gets for a=1 fully evaluated to:

    1 + 3   // left to right, or
    2 + 2   // right to left
    

    The result is the same = 4.

    An

    a++ * ++a    // or
    a++ == ++a
    

    would have undefined results. Isn't it?

提交回复
热议问题