If parenthesis has a higher precedence then why is increment operator solved first?

前端 未结 5 1754
梦谈多话
梦谈多话 2020-11-27 05:21

I have a single line code,

int a = 10;
a = ++a * ( ++a + 5);

My expected output was 12 * (11 + 5) = 192 ,but I got 187

5条回答
  •  离开以前
    2020-11-27 06:08

    Expressions are evaluated left to right. Parentheses (and precedence) just express grouping, they don't express ordering of evaluation.

    So

     11 * (12 + 5)
    ++a   ++a
    

    equals

    187
    

提交回复
热议问题