繁体   English   中英

短路操作员评估顺序

[英]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
}

为什么第二个printf给出答案0 1 2而不是0 2 1?

为什么第二个printf给出答案0 1 2而不是0 2 1?

&& 短路。

a=b&&++c||++d;

如果b0 ,则++c将不被评估。 因此c1而不是2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM