小编Sta*_*eon的帖子

C语言中的运算符优先级?

int x=12;
int y=7;
int z=19;
int sum;

sum = ++x >= y * 2 || y % 2 && z++ % 2;
Run Code Online (Sandbox Code Playgroud)

我对运算符优先级有点困惑?编译器在上面的代码中读取的第一个条件是什么?它是否会首先评估,y % 2 && z++ % 2因为&&优先级高于||,或者编译器仍然会从左到右并短路(如果最左边++x >= y * 2为真)?即编译器将按以下方式读取代码?

sum = (++x >= y * 2 || y % 2 )&& z++ % 2;
Run Code Online (Sandbox Code Playgroud)

c operator-precedence

1
推荐指数
2
解决办法
599
查看次数

标签 统计

c ×1

operator-precedence ×1