在C语言中,(x == y == z)的行为是否符合我的预期? [英] In C, does (x==y==z) behave as I'd expect?
本文介绍了在C语言中,(x == y == z)的行为是否符合我的预期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以像下面那样比较三个变量,而不是做 if((x == y)&&(y == z)&&(z = x))
? [如果所有三个变量都具有相同的值,则应执行if语句。这些是布尔值。]
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 variables have the same value. These are booleans.]
if(debounceATnow == debounceATlast == debounceATlastlast)
{
debounceANew = debounceATnow;
}
else
{
debounceANew = debounceAOld;
}
推荐答案
不,不是。
No, it does not.
x == y
转换为int ,得出 0
或 1
,然后将结果与 z $ c $进行比较c>。因此
x == y == z
将在且仅当(x等于y并且z为1)或(x不为等于y并且z为0)
x == y
is converted to int, yields 0
or 1
, and the result is compared to z
. So x==y==z
will yield true if and only if (x is equal to y and z is 1) or (x is not equal to y and z is 0)
您想要做的是
if(x == y && x == z)
这篇关于在C语言中,(x == y == z)的行为是否符合我的预期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文