以下程序的输出结果是( )。 #include <iostream> using namespace std; int main(){ int a=1,b; switch(a){

admin2013-02-27  7

问题 以下程序的输出结果是(    )。    #include <iostream>    using namespace std;    int main(){         int a=1,b;         switch(a){              case 1:b=30;              case 2:b=20;              case 3:b=10;              default:b=0;         }         cout<<b<<endl;         return 0;    }

选项 A、30
B、20
C、10
D、0

答案8

解析 由于在case分支的语句后没有出现跳转语句,所以程序将一直执行到switch语句结束。即逐步给变量b赋值30、20、10和0,最后b的值为0。
转载请注明原文地址:https://kaotiyun.com/show/ybNp777K
0

最新回复(0)