问题
单项选择题
有以下程序
#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=2,b=1
B.a=2,b=2
C.a=1,b=1
D.a=1,b=0
答案
参考答案:A
解析: 本题考查switch 语句的使用。switch 语句的执行过程为:进入switch结构后,对条件表达式进行运算,然后从上至下去找与条件表达式值相匹配的case,以此作为入口,执行switch结构中后面的各语句,直到遇到break语句,则跳出switch 语句,如果各case 都不匹配时,则执行default 后面的语句。