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++ - 禁用/重命名从主机环境 "env"导入

javascript - 像 "__proto__"这样的 javascript 属性名称在 ES5/6 中没有标准化吗?

asp.net - 是否可以在 ASP.NET Webforms 中实现新标准(例如 HTML5)?

c - 用 C 实现类

C 程序 - 从 LinkedList 中删除重复项

php - 新的 5.4 数组短数组语法 : Good practice?

c++ - C++ 标准规定的时间复杂度的操作可以动态分配内存吗?

c++ - 所有整数值都完美地表示为 double 吗?

c - 如何从 c 文件调用你的 yacc?

c - linux 上的段错误-在 windows 上工作