首页 > 试题广场 >

以下程序运行后的输出结果是( ...

[单选题]
以下程序运行后的输出结果是()
int main() {
    int a=1,b=2,m=0,n=0,k;
    k=(n=b<a)&&(m=a) ;
    printf("%d,%d\n",k,m);
    return 0;
}
  • 0,0
  • 0,1
  • 1,0
  • 1,1
& &逻辑与运算,先执行n=b<a,得n=0,赋值表达式的返回值为赋值符号右边的值,即0,逻辑与运算结束,不执行m=a。m未被赋值,仍为0。
编辑于 2019-01-16 18:43:50 回复(1)
(n=b<a)&&(m=a)  
&& 前面为假,后面 m=a 不执行
发表于 2020-08-11 20:15:02 回复(0)
<p>与运算在前一个判断错误就停止运行</p>
发表于 2020-06-14 18:38:04 回复(0)
&&惰性运算
发表于 2021-11-08 01:35:53 回复(0)
& &,短路与,前面为0,后面结果不影响,所以就不会执行了
发表于 2022-01-11 13:50:24 回复(0)
<p>&amp;运算符的短路效应</p>
发表于 2020-07-21 21:14:33 回复(0)
n=b<a判断为0后,对于&&运算,后面的m=a就不执行了,因为结果肯定为0
发表于 2020-02-28 16:03:41 回复(0)

表达式返回值为左值,&&需要左边成立才执行右边

发表于 2020-02-05 13:23:43 回复(0)
&&运算之前为0值,&&运算后语句不执行,故m=0;
发表于 2022-01-06 22:30:48 回复(1)

The logical AND operator (&&) returns true if both operands are true and returns false otherwise. The operands are implicitly converted to type bool before evaluation, and the result is of type bool. Logical AND has left-to-right associativity.

The operands to the logical AND operator don't need to have the same type, but they must have boolean, integral, or pointer type. The operands are commonly relational or equality expressions.

The first operand is completely evaluated and all side effects are completed before evaluation of the logical AND expression continues.

The second operand is evaluated only if the first operand evaluates to true (nonzero). This evaluation eliminates needless evaluation of the second operand when the logical AND expression is false.


发表于 2021-10-16 13:13:15 回复(0)
先算b<a
发表于 2023-10-30 16:24:12 回复(0)
&&的短路现象
发表于 2022-02-28 08:42:55 回复(0)
可我觉得n=b<a是个赋值运算啊 前者应该的为真啊,结果为1,0  
求大神为我讲解下  小弟万分感谢
发表于 2019-09-06 20:08:41 回复(1)