Why is a condition like (0 < a < 5) always true?

前端 未结 4 934
庸人自扰
庸人自扰 2020-11-29 13:56

I implemented the following program in C

    #include 
    int main() 
    {
       int a  = 10 ; 
       if(0 < a < 5) 
       {
               


        
4条回答
  •  时光说笑
    2020-11-29 14:26

      if(x

    It actually is valid syntax, but it doesn't do what you want.

    Realize that x returns a bool, i.e. true or false. You then compare it against whatever value "z" has. So the intention of "x" looks wrong.

    It can be:

    if(x < y && y < z)
    

提交回复
热议问题