小编use*_*138的帖子

运算符优先级和三元运算符

我的C语言有问题。

#include<stdio.h>
int main()
{
    int a = 10, b = 0, c = 7;
    if (a ? b : c == 0)
        printf("1");
    else if (c = c || a && b)
        printf("2");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这段代码显示2,但是我认为a:b:c返回b = 0,0 == 0返回1。您能解释一下代码吗?

c operator-precedence ternary

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

标签 统计

c ×1

operator-precedence ×1

ternary ×1