[英]Shortcircuit Operator Evaluation order
main()
{
int a,b=0,c=1,d=1;
a=++b&&++c||++d;
printf("%d %d %d",b,c,d); //1 2 1
b=0,c=1,d=1;
a=b&&++c||++d;
printf("%d %d %d",b,c,d); //0 1 2
}
Why second printf gives answer 0 1 2 instead of 0 2 1 ? 为什么第二个printf给出答案0 1 2而不是0 2 1?
Why second printf gives answer 0 1 2 instead of 0 2 1 ?
为什么第二个printf给出答案0 1 2而不是0 2 1?
&&
is short-circuiting. &&
短路。
In 在
a=b&&++c||++d;
++c
will not be evaluated if b
is 0
which is the case here. 如果
b
为0
,则++c
将不被评估。 Hence c
is 1
instead of 2
. 因此
c
是1
而不是2
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.