智慧职教: 分析下面代码: ( ) int x; double d = 1.5; switch (d) { case 1.0: x = 1; case 1.5: x = 2; case 2.0: x = 3; }
举一反三
- 若有float x; int a,b; ,下面四条switch语句中正确的有( )条。 switch(x) { case x=1.0: printf(“Y”); case x=2.0: printf(“N”); } switch(a) { case a=1: printf(“Y”); case a=2: printf(“N”); } switch(b) { case b==1: printf(“Y”); case b==2: printf(“N”); } switch(x) { case 1.0: printf(“Y”); case 2.0: printf(“N”); }
- 变量a,b,x已经通过语句int a=1, b=2;double x=4;声明,则下列选项中没有错误的是 A: switch(x%2){case 1:break} B: switch(x){case 1:break} C: switch((int)x%2){case 1:break} D: switch((a/2.0){case 1:break}
- 若有以下定义:float x;int a,b;则正确的switch语句是( ) A: switch(x){case 1.0:printf("* ");case 2.0:printf("** ");} B: switch(x){case 1,2:printf("* ");case 3:printf("** ");} C: switch(a+b){case 1:printf("* ");case 1+2:printf("** ");} D: switch(a){case b<1:printf("* ");case b>2:printf("** ");}
- 若有定义语句int a, b;double x;则下列选项中正确的是( ). A: switch(x%2) { case 0: a++; break; case 1: b++; break; default : a++; b++; } B: switch((int)x/2.0) { case 1: b++; break; case 0: a++; break; default : a++; b++; } C: switch((int)x%2) { case 0: a++; break; case 1: b++; break; default : a++; b++; } D: switch((int)(x)%2) { case 0.0: a++; break; case 1.0: b++; break; default : a++; b++; }
- int main()执行结果是(){int x=2,y=1; switch(x) { case 1: y=x ; break; case 2: y=-x ; case 3: y=x*3 ; break; case 4: y=4*x; } printf(“%d\n”,y);}