In C, does (x==y==z) behave as I'd expect?

前端 未结 3 414
甜味超标
甜味超标 2021-01-11 16:08

Can I compare three variables like the following, instead of doing if((x==y)&&(y==z)&&(z=x))? [The if statement should execute if all three vari

3条回答
  •  情话喂你
    2021-01-11 16:29

    No. The equality check associates from the left and the logical result is compared as a number, so that the expression 2 == 2 == 1 parses as (2 == 2) == 1, which in turn gives 1 == 1 and results in 1, which is probably not what you want.

提交回复
热议问题