下列程序的输出结果为______。 #include<iostream.h> void Func(char ch) { switch(ch) { case ’A’:case ’a’:

admin2013-05-30  22

问题 下列程序的输出结果为______。
   #include<iostream.h>
   void Func(char ch)
   {
       switch(ch)
       {
       case ’A’:case ’a’:
           cout<<"优秀"<<endl;
       case ’B’:case ’b’:
           cout<<"良好"<<endl;
           break;
      case ’C’:case ’c’:
           cout<<"及格"<<endl;
           break;
       default:
           cout<<"不及格"<<endl;
      }
   }
   void main( )
   {
       char ch1=’b’
       Func(ch1);
       Func(’A’);
   }

选项

答案良好 优秀 良好

解析 本题主要考察switch语句中break语句的使用。由于case A和 case B之间没有break语句,导致在输出“优秀”之后顺序执行并输出了 “良好”,这与原来的设计思路是不符的。
转载请注明原文地址:https://jikaoti.com/ti/1bE0FFFM
0

随机试题
最新回复(0)