单选题
若有定义:
float x=1.5;
int a=1, b=3, c=2;
则正确的switch语句是______。
A、
switch(a+b){case 1:printf("*/n");case 2+1:printf("**/n");}
B、
switch((int)x);{case 1:printf("*/n");case 2:printf("**/n");}
C、
switch(x){case 1.0:printf("*/n");case 2.0:printf("**/n");}
D、
switch(a+b){case 1:printf("*/n");case c:printf("**/n");}
【正确答案】
A
【答案解析】
[解析] switch语句的一般形式为:
switch(表达式){
case常量表达式1:语句1;
case常量表达式2:语句2;
default:语句n;
}
其中switch后的表达式只能是整型或字符型,故C选项错误;case后面必须是常量表达式,故D选项错误;switch()右括号后面不能有分号,故选项B错误,因此答案选A选项。
提交答案
关闭