Why is the statement using relation operators evaluate to 1 in the following code?

前端 未结 1 1264
太阳男子
太阳男子 2021-01-29 16:16

Shouldn\'t the value of i be 0? Since x

    #include

    int main(void)
    {
         int x = 10,y=20,z=5,i;
         i=x

        
相关标签:
1条回答
  • 2021-01-29 16:30

    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.

    0 讨论(0)
提交回复
热议问题