为什么在下面的代码中使用关系运算符的语句的结果为1? [英] Why is the statement using relation operators evaluate to 1 in the following code?
本文介绍了为什么在下面的代码中使用关系运算符的语句的结果为1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i的值不应该为0吗? 由于x
Shouldn't the value of i be 0? Since x
#include<stdio.h>
int main(void)
{
int x = 10,y=20,z=5,i;
i=x<y<z;
printf("%d",i);
return 0;
}
推荐答案
在您的代码中,由于 LTR关联性的关系运算符,
In your code, due to the LTR associativity of the relational operators,
i=x<y<z;
评估为
i=(x<y)<z;
这是
i=(10<20)<z;
这是
i= 1 < 5;
为TRUE(1).该1
被存储在i
中.就是这样.
which is TRUE (1). That 1
gets stored in i
. That's it.
这篇关于为什么在下面的代码中使用关系运算符的语句的结果为1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文