#QMCP0001. C++ L1-2 期末练习 2607

C++ L1-2 期末练习 2607

一、单项选择题

  1. 以下哪个是正确的 C++ 程序基本结构?( )

{{ select(1) }}

  • #include <bits/stdc++.h> using namespace std; int main() { return 0; }
  • #include int main() { return 0; }
  • #include <stdio.h> void main() { }
  • import iostream; int main() { return 0; }
  1. 下列变量名定义合法的是?( )

{{ select(2) }}

  • 2num
  • _score
  • int
  • a@b
  1. 执行以下代码后,变量 x 的值是多少?( )
int x = 17 / 4 + 17 % 4;

{{ select(3) }}

  • 8
  • 6
  • 5
  • 4
  1. 在 C++ 中,int 类型变量通常占用多少字节?( )

{{ select(4) }}

  • 1个字节
  • 2个字节
  • 4个字节
  • 8个字节
  1. 字符 'A' 的 ASCII 码是 65,那么字符 'D' 的 ASCII 码是?( )

{{ select(5) }}

  • 66
  • 67
  • 68
  • 69
  1. 下列表达式中,结果为 true 的是?( )

{{ select(6) }}

  • 5 == 5 && 5 < 3
  • 5 != 3 || 5 < 3
  • !(5 > 3)
  • 5 >= 5 && 5 > 6
  1. 以下代码的输出结果是?( )
int a = 8;
if (a % 2 == 0) cout << "偶数";
else cout << "奇数";

{{ select(7) }}

  • 奇数
  • 偶数
  • 什么都不输出
  • 编译错误
  1. 逻辑表达式 !(a > 5 && a < 10) 等价于以下哪个?( )

{{ select(8) }}

  • a <= 5 || a >= 10
  • a <= 5 && a >= 10
  • a > 5 || a < 10
  • a < 5 && a > 10
  1. 关于 switch 语句,以下说法正确的是?( )

{{ select(9) }}

  • case 后面可以跟变量
  • case 后面必须是常量表达式
  • switch 后面可以跟浮点数
  • case 分支中不能有多条语句
  1. 以下 for 循环执行完后,变量 sum 的值是多少?( )
int sum = 0;
for (int i = 1; i <= 5; i++) sum += i;

{{ select(10) }}

  • 10
  • 15
  • 20
  • 25
  1. 以下代码的输出结果是?( )
for (int i = 0; i < 4; i += 2) cout << i << " ";

{{ select(11) }}

  • 0 1 2 3
  • 0 2
  • 0 2 4
  • 1 3
  1. 以下嵌套循环代码的输出结果是?( )
for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= i; j++) cout << "*";
    cout << endl;
}

{{ select(12) }}

  • *  
    **  
    ***
    
  •   * 
     **
    ***
    
  • ***
    **
    *
    
  • *
    *
    *
    
  1. 定义一个包含 10 个 int 元素的数组,以下语法正确的是?( )

{{ select(13) }}

  • int a[10];
  • int a = new int[10];
  • int[10] a;
  • array<int, 10> a;
  1. 已知数组 int a[5] = {3, 7, 2, 9, 5};,以下代码的功能是?( )
int m = a[0];
for (int i = 1; i < 5; i++)
    if (a[i] > m) m = a[i];

{{ select(14) }}

  • 求数组的最小值
  • 求数组的最大值
  • 求数组元素的和
  • 求数组元素的平均值
  1. 以下代码实现了什么功能?( )
int x, cnt = 0;
cin >> x;
for (int i = 0; i < n; i++)
    if (a[i] == x) cnt++;

{{ select(15) }}

  • 统计数组中等于 x 的元素个数
  • 查找数组中第一个等于 x 的位置
  • 判断数组中是否有元素等于 x
  • 将数组中等于 x 的元素置为 0
  1. 以下 while 循环的执行次数是?( )
int i = 0;
while (i < 5) {
    cout << i;
    i++;
}

{{ select(16) }}

  • 4次
  • 5次
  • 6次
  • 无限次
  1. 以下代码的功能是?( )
int n;
cin >> n;
while (n > 0) {
    cout << n % 10;
    n /= 10;
}

{{ select(17) }}

  • 输出 n 的各位数字之和
  • 输出 n 的位数
  • 逆序输出 n 的每一位数字
  • 计算 n 的阶乘
  1. 在 C++ 中,要按指定宽度输出整数,需要使用的头文件和控制符是?( )

{{ select(18) }}

  • #include <iomanip> 和 setw()
  • #include <iostream> 和 printf()
  • #include <cstdio> 和 scanf()
  • #include <format> 和 format()
  1. 定义双精度浮点数应使用的关键字是?( )

{{ select(19) }}

  • float
  • double
  • long float
  • real
  1. 已知 char s[] = "Hello";,数组 s 的长度(包含\0)是?( )

{{ select(20) }}

  • 5
  • 6
  • 4
  • 10
  1. 已知 char s1[] = "abc", s2[] = "def";,将 s2 连接到 s1 末尾应使用的函数是?( )

{{ select(21) }}

  • strcpy(s1, s2)
  • strcat(s1, s2)
  • strcmp(s1, s2)
  • strlen(s1, s2)
  1. 对于 C++ 的 string 类型,以下操作正确的是?( )

{{ select(22) }}

  • string s = "abc"; s[0] = 'x';
  • string s; s = 123;
  • string s = "abc"; int len = s.length;
  • string s; scanf("%s", s);
  1. 以下关于 C++ 函数的说法,正确的是?( )

{{ select(23) }}

  • 函数必须有返回值
  • 函数必须定义在 main 函数之前
  • 函数的形参可以与实参同名
  • 一个函数不能调用另一个函数
  1. 已知结构体定义如下,以下赋值正确的是?( )
struct Student {
    string name;
    int age;
    float score;
};

{{ select(24) }}

  • Student s = {"Tom", 18, 85.5};
  • Student s; name = "Tom";
  • s.name = "Tom";
  • Student.name = "Tom";
  1. 以下代码的输出结果是?( )
char s[] = "Hello";
cout << strlen(s);

{{ select(25) }}

  • 5
  • 6
  • 4
  • 0

二、判断题(共10题)

  1. 变量名可以以下划线 _ 开头。( )

{{ select(26) }}

  • 正确
  • 错误
  1. 表达式 5 + 3 * 2 的结果为 16。( )

{{ select(27) }}

  • 正确
  • 错误
  1. char 类型变量可以存储一个字符,也可以存储对应的 ASCII 码整数值。( )

{{ select(28) }}

  • 正确
  • 错误
  1. if-else if 多分支语句中,当某个条件满足时,其他分支也会被执行。( )

{{ select(29) }}

  • 正确
  • 错误
  1. 以下循环中,循环变量 i 的取值范围是 0 到 9。( )
for (int i = 0; i < 10; i++)

{{ select(30) }}

  • 正确
  • 错误
  1. 已知有数组 int a[10],数组下标从 0 开始,访问 a[10] 时不会越界。( )

{{ select(31) }}

  • 正确
  • 错误
  1. while 循环先判断条件再执行循环体,do-while 循环先执行循环体再判断条件。( )

{{ select(32) }}

  • 正确
  • 错误
  1. C++ 中的 string 类型可以直接通过下标修改其中的字符。( )

{{ select(33) }}

  • 正确
  • 错误
  1. 为避免计算结果和预期不一致,函数的返回值类型要与函数体内 return 语句的表达式类型一致。( )

{{ select(34) }}

  • 正确
  • 错误
  1. 结构体中可以包含多个不同类型的成员变量。( )

{{ select(35) }}

  • 正确
  • 错误