若有定义:float w;int a,b;则合法的switch语句是( )。

admin2014-10-20  23

问题 若有定义:float w;int a,b;则合法的switch语句是(    )。

选项 A、switch(w)
B、switch(a);
{case 1.0:printf(“*\n”);  {case 1 printf(“*\n”);
case 2.0:printf(“**\n”);case 2 printf(“**\n”);
}}
C、switch(b)
D、switch(a+b);
{case 1:printf(“*\n”);{case 1:printf(“*\n”);
default:printf(“\n”);case 2:printf(“**\n”);
case 1+2:printf(“**\n”);default:printf(“\n”);
}}

答案C

解析 A项switch后面的表达式不能为浮点型表达式,一般为整型或字符型。B、D,switch后面有;不满足switch的规则。只有C,default可以在case前也可以在其后,故选C。
转载请注明原文地址:https://kaotiyun.com/show/EuvR777K
0

最新回复(0)