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

标签 c standards

标准是否保证 !!(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/

相关文章:

c - 我怎样才能在C中将日期转换为可读的英文格式

colors - 标准化的颜色名称?

关于继承成员地址的 C++ 标准

c++ - 是否可以同时有两个或多个事件异常?

c - 以不规则速率存储二维数据

c - 使用 fopen 写入闪存驱动器

c - 权威 C 书籍指南和 list

c - 用C语言进行windows编程

c++ - 为什么初始化列表不能作为main的参数?怎么提议呢?

c - 取malloc()、realloc()和free()的地址是否可移植?