gpt4 book ai didi

c - C 中的内部短路评估

转载 作者:行者123 更新时间:2023-11-30 21:41:11 26 4
gpt4 key购买 nike

我知道Java和C/C++有短路计算,即,在if (a && b)中,如果a<,b将永远不会计算 不是真的。

但是如果我有像 if ( (a && b) OP c ) 这样的表达式(其中 OP 是任意逻辑运算符),将会 b 评估是否a = false?谢谢。

最佳答案

C 标准是这么说的 -

6.5.13 Logical AND operator

  1. The && operator guarantees left-to-right evaluation.......If the first operand compares equal to 0, the second operand is not evaluated.

因此,如果 a==flase b 将不会被评估。

关于c - C 中的内部短路评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32411280/

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