若有定义:floatx=1.5;inta=1,b=3,c=2;则正确的switch语句是

若有定义:floatx=1.5;inta=1,b=3,c=2;则正确的switch语句是
A.switch(x)
{case1.0:printf("*\n");
case2.0:printf("**\n");}
B.switch((int)x);
{case1:printf("*\n");
case2:printf("**\n");}
C.switch(a+b)
{case1:printf("*\n");
case2+1:printf("**\n");}
D.switch(a+b)
{case 1:printf("*\n");
case c:printf("**\n");}
请求详解
最远的云 1年前 已收到1个回答 举报

娃哈哈ea85 幼苗

共回答了11个问题采纳率:81.8% 举报

选 C。
A错,因为浮点型不能用在 switch中。
B错,本来将浮点型强制转换为整型之后用switch是可以的,但它在swich((int)x)后面多了个分号。
C对,a+b的结果也是整型,没问题。
D错,因为 case 后面只能跟常量,不能跟变量。所以不能 case c。

1年前

7
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.035 s. - webmaster@yulucn.com