有以下程序 #include<stdio.h> main() {intx=1 y=0 a=0 b=0; switch(x) {case1: switch
程序
已帮助 人
有以下程序
#include <stdio.h>
main()
{ int x=1,y=0,a=0,b=0;
switch(x)
{ case 1:
switch(y)
{ case 0:a++; break;
case 1:b++; break;
}
case 2:a++; b++; break;
case 3:a++; b++;
}
printf("a=%d,b=%d\n",a,b);
}
程序的运行结果是
A.a=1,b=0
B.a=2,b=2
C.a=1,b=1
D.a=2,b=1
-
正确答案:D
解析:本题考查switch语句,首先,x=1符合条件case 1,执行switch(y)语句,y=0符合case 0语句,执行a++并跳出switch(y)语句,此时a=1。因为case 1语句后面没有break语句,所以向后执行case 2语句,执行a++,b++,然后跳出switch(x),得a=2,b=1。
