用C双重否定:这是保证返回0/1? [英] double negation in C : is it guaranteed to return 0/1?
问题描述
为 !!(X)
担保的标准返回0/1?
Is !!(x)
guaranteed by the standard to return 0/1?
请注意,我的不可以问C ++,其中布尔类型定义。
Note that I am not asking about c++, where a bool type is defined.
推荐答案
是的,在C99,见§6.5.3.3/ 4:
Yes, in C99, see §6.5.3.3/4:
逻辑否定运算符的结果!为 0 如果操作数的值进行比较
不等于0, 1 如果它的操作数的值进行比较,等于0的结果类型的内部即可。
这位前pression!E是等于(0 == E)。
The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int. The expression !E is equivalent to (0==E).
所以!X
和 !!是
只能得到0或1,为 INT
秒。
So !x
and !!y
can only yield 0 or 1, as int
s.
有关其他运营商,在C99,也见是在"真"结果>中&LT ;,,&安培;!&放;, ||或==界定?
For other operators, in C99, see also Is the "true" result of >, <, !, &&, || or == defined?
这篇关于用C双重否定:这是保证返回0/1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!