简体   繁体   中英

C++ Operator Precedence example

I am trying to figure out how the following expression is grouped according to precedence:

int x = 0, y = 0;
someValue ? ++x, ++y : --x, --y;

When someValue is 0 (false) the second part is evaluated, and both x and y become -1. However if someValue is 1 (true) then somehow x becomes 1 but y remains 0, which means the second part of the conditional expression is evaluated too, but only the --y part, which I assume is because of the comma operator, but I can't for the life of me figure out how this is achieved. Any insight would be appreciated.

,具有所有运算符的最低优先级,因此您的表达式被解析为

(someValue ? ++x, ++y : --x), --y;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM