#KS1001. C++考试(选择题)

C++考试(选择题)

一、选择题(共15道,每题4分)

1、下列属于C++合法变量名的是( )。 {{ select(1) }}

  • 1name
  • name_1
  • name‑1
  • int

2、int a = 7; cout << a % 3; 的输出结果是( )。 {{ select(2) }}

  • 0
  • 1
  • 2
  • 3

3、C++中 continue 的作用是( )。 {{ select(3) }}

  • 终止整个循环
  • 跳过本次循环剩下语句,直接进入下一轮循环
  • 终止程序运行
  • 跳出switch

4、定义 char s[] = "test";,strlen(s) 的值是( )。 {{ select(4) }}

  • 4
  • 5
  • 6
  • 不确定

5、函数传值调用时,函数内部修改形参,实参( )。 {{ select(5) }}

  • 同步跟着改变
  • 不会发生变化
  • 会变成随机值
  • 会被置0

6、下面哪一个是C++单行注释( )。 {{ select(6) }}

  • /* 注释 */
  • //注释
  • #注释
  • --注释

7、下面数字中,属于素数的是( )。 {{ select(7) }}

  • 4
  • 9
  • 7
  • 12

8、执行 cout << (3>2 ? 10 : 20); 输出结果为( )。 {{ select(8) }}

  • 3
  • 2
  • 10
  • 20

9、

#include <iostream>
using namespace std;
int main()
{
    int arr[5]={10,20,30,40,50};
    cout << arr[3];
    return 0;
}

程序输出结果是( )。 {{ select(9) }}

  • 20
  • 30
  • 40
  • 50

10、

char str[] = "abc123";
str[3] = '\0';
cout << str;

输出结果是( )。 {{ select(10) }}

  • abc123
  • abc
  • abc\0
  • 123

11、

#include <iostream>
using namespace std;
int main()
{
    int sum=0;
    for(int i=1;i<=6;i++)
    {
        if(i%2==0) continue;
        sum += i;
    }
    cout << sum;
    return 0;
}

输出为( )。 {{ select(11) }}

  • 6
  • 9
  • 12
  • 21

12、

#include <iostream>
using namespace std;
int main()
{
    int a=8;
    if(a>10)
        cout<<"A";
    else if(a>5)
        cout<<"B";
    else
        cout<<"C";
    return 0;
}

输出结果是( )。 {{ select(12) }}

  • A
  • B
  • C
  • 无输出

13、

#include <iostream>
using namespace std;
int main()
{
    int arr[6]={5,2,8,1,9,3};
    int maxv = arr[0];
    for(int i=1;i<6;i++)
    {
        if(arr[i]>maxv)
            maxv = arr[i];
    }
    cout << maxv;
    return 0;
}

程序输出结果为( )。 {{ select(13) }}

  • 8
  • 9
  • 5
  • 3

14、

#include <iostream>
using namespace std;
int main()
{
    int cnt = 0;
    for(int i = 1; i <= 20; i++)
    {
        if(i % 3 == 0 || i % 5 == 0)
        {
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}

程序输出结果是( )。 {{ select(14) }}

  • 8
  • 9
  • 10
  • 11

15、

#include <iostream>
using namespace std;
int main()
{
    int sum = 0;
    for(int i = 1; i <= 4; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            sum += j;
        }
    }
    cout << sum;
    return 0;
}

程序输出结果是( )。 {{ select(15) }}

  • 10
  • 15
  • 20
  • 30