#GESP202606C4T2. 判断题(每题 2 分,共 20 分)

判断题(每题 2 分,共 20 分)

  1.  \ 运行以下程序后,变量 a 的值最终会变为 2020
void modify(int *p) {
    *p = *p + 10;
}
int main() {
    int a = 10;
    modify(&a);
    return 0;
}

{{ select(1) }}

  • 正确
  • 错误

  1.  \ 在 C++ 中,引用一旦初始化并绑定到某个变量后,可以通过赋值语句将其重新绑定到另一个变量。

{{ select(2) }}

  • 正确
  • 错误

  1.  \ 下面程序可以正确计算并输出 33 名学生的平均成绩。
struct Student {
    int id;
    int score;
};
int main() {
    Student students[3] = {
        {1, 90},
        {2, 80},
        {3, 100}
    };
    int sum = 0;
    for (int i = 0; i < 3; i++) {
        sum += students[i].score;
    }
    double average = sum / 3.0;
    cout << average << endl;
    return 0;
}

{{ select(3) }}

  • 正确
  • 错误

  1.  \ 选择排序算法在寻找每一轮最小值时,如果遇到相等的元素不进行交换,则选择排序是一种稳定的排序算法。

{{ select(4) }}

  • 正确
  • 错误

  1.  \ 如果使用带 flag 的冒泡排序,且待排序数组一开始就是有序的,那么算法只需一轮扫描即可结束,时间复杂度为 O(n)O(n)

{{ select(5) }}

  • 正确
  • 错误

  1.  \ 在 C++ 中定义二维数组并初始化时,可以省略第一维,但不能省略第二维。因此 int a[][2] = {{1, 2}, {3, 4}}; 是合法的,而 int a[][] = {{1, 2}, {3, 4}}; 是不合法的。

{{ select(6) }}

  • 正确
  • 错误

  1.  \ 下面代码的时间复杂度是 O(n2)O(n^2)
int cnt = 0;
for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
        cnt++;
    }
}

{{ select(7) }}

  • 正确
  • 错误

  1.  \ 假设文件 output.txt 能正常打开,下面代码通过 rdbufcout 的输出重定向到了文件中。
ofstream fout("output.txt");
streambuf* old_buf = cout.rdbuf();
cout.rdbuf(fout.rdbuf());
cout << "GESP Exam";
cout.rdbuf(old_buf);

{{ select(8) }}

  • 正确
  • 错误

  1.  \ 小杨想通过下面程序给饭卡充值,程序会输出 7070
void recharge(int money) {
    money += 20;
}
int main() {
    int card = 50;
    recharge(card);
    cout << card;
    return 0;
}

{{ select(9) }}

  • 正确
  • 错误

  1.  \ 下面代码可以通过编译。
int a[5];
a++;

{{ select(10) }}

  • 正确
  • 错误