关于逻辑运算符的问题 [英] Question about logical operators

查看:124
本文介绍了关于逻辑运算符的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <conio.h>
void main()
{
int a=5,b=10,c=15;


int d=a||b&&c;

printf("%d",d);
getch();
}



输出为true 1,但我不明白该输出是如何产生的.



The output is true 1, but I do not understand how this output comes.

推荐答案

在C中,任何非零值均为true,而只有零为false.因此,在评估表达式时(并忽略优先级规则,因为它们在此示例中无关紧要),
In C, any non-zero value is true, and only zero is false. So, when evaluating your expression (and ignoring precedence rules because they don''t matter in this example)
true OR true AND true

始终为true.因此将返回一个非零值.在这种情况下,C编译器为true返回1.简单!

will always be true. So a non-zero value will be returned. In this case, the C compiler returns 1 for true. Simples!


||和&&认为任何非零为true
他们是布尔运算符
|| and && consider any non zero as true
they are boolean oprators


这篇关于关于逻辑运算符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆