如何我==(20 || 10)评估? [英] How is i==(20||10) evaluated?
本文介绍了如何我==(20 || 10)评估?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <stdio.h>
int main(void)
{
int i=10;
if(i==(20||10))
printf("True");
else
printf("False");
return 0;
}
这使输出的假的
请向我解释如何做到这一点工作方案?
Please explain to me how does this program work?
推荐答案
这行如果(我==(20 || 10))
始终计算为我== 1
为中Alk
注释中说的 - (20 || 10)
计算结果为 1
,因此,当你比较我== 1
,这就是为什么你会得到假
作为输出。在 C
非零值意味着真。
This line if(i==(20||10))
always evaluates to i==1
as Alk
said in comments - (20||10)
evaluates to 1
, hence when you compare i == 1
, that is why you get False
as the output. A non-Zero value in C
implies true.
阅读短路评价
也许这就是你想要的:
int i=10;
if(i==20 || i == 10)
printf("True");
else
printf("False");
这篇关于如何我==(20 || 10)评估?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文