是"真"结果>中&LT ;,,&安培;!&放;, ||或==界定? [英] Is the "true" result of >, <, !, &&, || or == defined?

查看:90
本文介绍了是"真"结果>中&LT ;,,&安培;!&放;, ||或==界定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我比如写 7→1 C(下称C99如果这不是一个始终被功能),我希望得到的结果将完全1只是一些非零值?这是否适用于所有的布尔操作?

When I for instance write 7>1 in C (say C99 if this is not an always-been feature), can I expect the result will be exactly 1 or just some non-zero value? Does this hold for all bool operators?

推荐答案

在C99§6.5.8关系运算符,项目6(< > < = > =

In C99 §6.5.8 Relational Operators, item 6 (<,>,<= and >=):

每个运营商和LT的; (小于),>(大于),LT =(小于或等于),和> =
  (大于或等于)应产生的 1 如果指定的关系是真实和 0 如果是假的)
  结果类型的内部

Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false) The result has type int.

至于平等的运营商,这是一个有点进一步§6.5.9( == !=

As for equality operators, it's a bit further in §6.5.9 (== and !=):

的==(等于),!=(不等于)运算类似于关系
  除了其较低的precedence运营商)各运营商产量的 1 如果在中
  指定的关系是真实和 0 如果是假的。结果类型的内部即可。对于任何一对
  操作数的关系,只有一个是真的。

The == (equal to) and != (not equal to) operators are analogous to the relational operators except for their lower precedence) Each of the operators yields 1 if the specified relation is true and 0 if it is false. The result has type int. For any pair of operands, exactly one of the relations is true.

的逻辑与和逻辑或尚未有点进一步§6.5.13(&放大器;&安培;

The logical AND and logical OR are yet a bit further in §6.5.13 (&&)

&将功放;&安培;经营者应当产生的 1 如果两个操作数的比较不等于0;否则,它
  收益率 0 。结果类型的内部

The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it yields 0. The result has type int.

...和§6.5.14( ||

... and §6.5.14 (||)

该||经营者应当产生的 1 如果任一操作数的比较不等于0;否则,它
  收益率 0 。结果类型的内部

The || operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it yields 0. The result has type int.

和一元算术运算符的语义 超过在§6.5.3.3/ 4:!

And the semantics of the unary arithmetic operator ! are over at §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).

结果类型为 INT 一刀切,用 0 1 作为可能的值。 (除非我错过了一些。)

Result type is int across the board, with 0 and 1 as possible values. (Unless I missed some.)

这篇关于是&QUOT;真&QUOT;结果&gt;中&LT ;,,&安培;!&放;, ||或==界定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆