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

前端 未结 3 416
甜味超标
甜味超标 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:16

    You can actually type something like this:

    int main()
    {
            const int first = 27,
                      second = first,
                      third = second,
                      fourth = third;
            if (!((first & second & third) ^ fourth))
                return 1;
            return 0;
    }
    

提交回复
热议问题