Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
表达式c=a>;的输出是什么;2+;b=6._C_Operator Precedence_Evaluation - Fatal编程技术网

表达式c=a>;的输出是什么;2+;b=6.

表达式c=a>;的输出是什么;2+;b=6.,c,operator-precedence,evaluation,C,Operator Precedence,Evaluation,最近我遇到了这个节目 #include <stdio.h> int main() { int a = 10, b = 20, c; c = a > 2 + b != 6; printf("%d", c); } #包括 int main(){ INTA=10,b=20,c; c=a>2+b!=6; printf(“%d”,c); } 输出1背后的逻辑是什么?它取决于 +的优先级高于,的优先级高于= a > 2 + b != 6 评估结果如下:

最近我遇到了这个节目

#include <stdio.h>

int main() {
    int a = 10, b = 20, c;
    c = a > 2 + b != 6;
    printf("%d", c);
}
#包括
int main(){
INTA=10,b=20,c;
c=a>2+b!=6;
printf(“%d”,c);
}
输出
1
背后的逻辑是什么?

它取决于

+
的优先级高于
的优先级高于
=

a > 2 + b != 6
评估结果如下:

((a > (2 + b)) != 6)
或者更具体地说:

((10 > (2 + 20)) != 6)
其中
(10>(20+2))
计算为
0
,因为
10
不大于
22

因此,表达式展开为:

(0 != 6)

它的计算结果是
1
,因为
0
不等于
6
->
(0!=6)==1

一个很好的练习是手动添加反映操作顺序的正确括号,这样您就可以自己查看了。我很困惑。你的标题是“C”语言,但是你的标签有C++语言。你用哪种语言编程?C语言和C++语言是不同的语言。请适当地编辑你的标签。C或C++都会给出相同的结果@ ThomasMatthews