单选题
下列选项中与if(a==1)a=b;else a++;语句功能不同的switch语句是______。
A、
switch(a==1){case 0:a=b;break;case 1:a++;}
B、
switch(a){case 1:a=b;break;default:a++;}
C、
switch(a){default:a++;break;case 1:a=b;}
D、
switch(a==1){case 1:a=b;break;case 0:a++;}
【正确答案】
A
【答案解析】
[解析] if语句的含义是:如果a的值为1,将b的值赋给a,否则将a的值自增1。选项A中,switch(a==1)中表达式a==1的结果如果为真,即为1,则从case1开始执行a++;如果a==1的结果为假,即0,则从case0开始执行a=b,所以与题于含义执行操作相反的是选项A中的语句。
提交答案
关闭