14.16 Boolean expressions

本文详细介绍了布尔表达式的定义及其在条件语句中的使用规则。解释了如何将不同类型的表达式转换为布尔值,并讨论了实现true和false操作符的类型的要求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A boolean-expression is an expression that yields a result of type bool.
boolean-expression:
expression
The controlling conditional expression of an if-statement (?5.7.1),
while-statement (?5.8.1), do-statement
(?5.8.2), or for-statement (?5.8.3) is a boolean-expression. The
controlling conditional expression of the
?: operator (?4.12) follows the same rules as a boolean-expression, but
for reasons of operator precedence
is classified as a conditional-or-expression.
A boolean-expression is required to be of a type that can be implicitly
converted to bool or of a type that
implements operator true. [Note: As required by ?7.9.1, any type that
implements operator true
must also implement operator false. end note] If neither requirement is
satisfied, a compile-time error
occurs.
When a boolean expression is of a type that cannot be implicitly converted
to bool but does implement
operator true, then following evaluation of the expression, the operator
true implementation
provided by that type is invoked to produce a bool value.
[Note: The DBBool struct type in ?8.4.2 provides an example of a type that
implements operator true
and operator false. end note]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值