有以下程序 #include <stdio.h> main() { int x=1,y=0,a=0,b=0; switch(x) { case 1: switch(y)

admin2010-09-05  25

问题 有以下程序    #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。
转载请注明原文地址:https://kaotiyun.com/show/ycWp777K
0

最新回复(0)