问题
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;
}
回答1:
In your code, due to the LTR associativity of the relational operators,
i=x<y<z;
evaluates to
i=(x<y)<z;
which is
i=(10<20)<z;
which is
i= 1 < 5;
which is TRUE (1). That 1
gets stored in i
. That's it.
来源:https://stackoverflow.com/questions/34481683/why-is-the-statement-using-relation-operators-evaluate-to-1-in-the-following-cod