why parenthesis is unable to change c++ operator precedence in this case?

前端 未结 5 670
野的像风
野的像风 2021-01-29 15:24

Here\'s my simple code:

int main()
{
    int x = 5;
    cout << (x++) << endl;

    return 0;
}

the code above prints 5

5条回答
  •  情话喂你
    2021-01-29 16:16

    The expression (x++), with or without parentheses, evaluates to the previous value of x, and has the side-effect of increasing x.

    If you want to see the effect of the increase then use the obscure

    cout << (x++, x) << endl;
    

提交回复
热议问题