1.以下程序的输出结果是()
#include <iostream.h>
int main()
{
int x=3,y=3;
switch(x%2)
{
case 1:
switch (y)
{
case 0:
cout<<"first";
case 1:
cout<<"second";
break;
default:
cout<<"hello";
}
case 2:
cout<<"third";
}
return 0;
}
A second third
B hello
C first second
D hellothird
看到case我们就需要注意break是否存在了,x%2 = 1,进入case1;y=3,进入default语句;把hello打印出来default后没有break语句跳出循环,所以还是要执行case2,再打印出third,最后打印出来的是hellothird
2.以下能对二维数组a进行正确初始化的语句是()
A int ta[2][]={
{0,1,2},{3,4,5}};
B int ta[][3]={
{0,1,2},{3,4,5}};
C int ta[2][4]={
{0,1,2},{3,4},{5}};
D int ta[][3]={
{0,2},{},{3,4,5}};
解析: