#1064. GESP C++ 四 级 2026年6月真题 · 判断题
GESP C++ 四 级 2026年6月真题 · 判断题
GESP C++ 四 级 2026年6月真题(120 分钟,总分 100 分)
判断题(共 10 题,每题 2 分,共 20 分)
1. 运行以下程序后,变量 a 的值最终会变为 20。
void modify(int *p) {
*p = *p + 10;
}
int main() {
int a = 10;
modify(&a);
return 0;
}
{{ select(1) }}
- 正确
- 错误
2. 在 C++ 中,引用一旦初始化并绑定到某个变量后,可以通过赋值语句将其重新绑定到另一个变量。
{{ select(2) }}
- 正确
- 错误
3. 下面程序可以正确计算并输出3名学生的平均成绩。
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) }}
- 正确
- 错误
4. 选择排序算法在寻找每一轮最小值时,如果遇到相等的元素不进行交换,则选择排序是一种稳定的排序算法。
{{ select(4) }}
- 正确
- 错误
5. 如果使用带 flag 的冒泡排序,且待排序数组一开始就是有序的,那么算法只需一轮扫描即可结束,时间复杂度为 O(n)。
{{ select(5) }}
- 正确
- 错误
6. 在 C++ 中定义二维数组并初始化时,可以省略第一维,但不能省略第二维。因此 int a[][2] = {{1, 2}, {3, 4}}; 是合法的,而 int a[][] = {{1, 2}, {3, 4}}; 是不合法的。
{{ select(6) }}
- 正确
- 错误
7. 下面代码的时间复杂度是 O(2n)。
int cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cnt++;
}
}
{{ select(7) }}
- 正确
- 错误
8. 假设文件 output.txt 能正常打开,下面代码通过 rdbuf 将 cout 的输出重定向到了文件中。
ofstream fout("output.txt");
streambuf* old_buf = cout.rdbuf();
cout.rdbuf(fout.rdbuf());
cout << "GESP Exam";
cout.rdbuf(old_buf);
{{ select(8) }}
- 正确
- 错误
9. 小杨想通过下面程序给饭卡充值,程序会输出 70。
void recharge(int money) {
money += 20;
}
int main() {
int card = 50;
recharge(card);
cout << card;
return 0;
}
{{ select(9) }}
- 正确
- 错误
10. 下面代码可以通过编译。
int a[5];
a++;
{{ select(10) }}
- 正确
- 错误
相关
在下列比赛中: