gpt4 book ai didi

c - C : is it guaranteed to return 0/1? 中的双重否定

转载 作者:太空狗 更新时间:2023-10-29 16:20:36 25 4
gpt4 key购买 nike

标准是否保证 !!(x) 返回 0/1?

请注意,我不是询问有关定义 bool 类型的 c++。

最佳答案

是的,在 C99 中,请参阅 §6.5.3.3/4:

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!!y 只能产生 0 或 1,作为 int

对于其他运算符,在 C99 中,另请参阅 Is the "true" result of >, <, !, &&, || or == defined?

关于c - C : is it guaranteed to return 0/1? 中的双重否定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8617090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com