若有以下程序 #include <stdio.h> main() { int a=1,b=2,c=3,d=4, r=0; if (a!=1) ; else r=1; if (b==2) r+=2

admin2021-06-15  29

问题 若有以下程序
    #include <stdio.h>
    main()
    {  int  a=1,b=2,c=3,d=4, r=0;
       if (a!=1) ;  else  r=1;
       if (b==2)  r+=2;
       if (c!=3);  r+=3;
       if (d==4)  r+=4;
       printf("%d\n", r);
    }
则程序的输出结果是

选项 A、3
B、7
C、6
D、10

答案D

解析 第一个if语句a!=1条件为假,所以执行else后的语句r=1,第二个if语句b==2条件成立,执行r+=2,r的值变为3,第三个if语句c!=3条件为假,所以不做任何操作,执行下面的r+=3操作,r的值变为6,判断第四个if条件,d==4条件成立,执行r+=4操作,结果为10。
转载请注明原文地址:https://kaotiyun.com/show/h8tp777K
0

最新回复(0)