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

前端 未结 5 662
野的像风
野的像风 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:06

    This is because x++ evaluates the value of x (5 in your case) and will increase its value after that....

    what you are looking for is the pre-increment, also ++x

提交回复
热议问题