佛大附属信奥 在线评测 · 分级学习
登录

GESP C++ 四级 · 2026 年 6 月认证理论卷

登录 后作答才能记录成绩

一、单选题(每题 2 分)

1. ⼩杨正在编写⼀个"数字交换器"程序,他希望通过函数交换两个变量的值。请问运⾏以下代码后,屏幕上输出的是( )。 ```cpp void exchange(int *a, int &b) { int t = *a; *a = b; b = t; } int main() { int x = 100, y = 200; exchange(&x, y); cout << x << " " << y; return 0; } ```
2. 下⾯程序想通过函数计算三门课总分,横线处应填⼊的是( )。 ```cpp int sumScore(int a, int b, int c) { return a + b + c; } int main() { int chinese = 88, math = 95, english = 90; int total = __________; cout << total; return 0; } ```
3. 下⾯程序输出结果是( )。 ```cpp int addOne(int x) { return x + 1; } int main() { int a = 6; cout << addOne(a) + addOne(3); return 0; } ```
4. 关于下⾯程序,说法正确的是( )。 ```cpp void show() { int stars = 5; } int main() { cout << stars; return 0; } ```
5. ⼩杨在调试⼀个"等级提升"系统,代码逻辑如下,执⾏后 `*p` 的值是( )。 ```cpp int lv = 5, next_lv = 6; int *p = &lv; *p = *p + 1; p = &next_lv; ```
6. ⼩杨正在开发⼀款名为"星际⽹格"的游戏,他⽤⼆维数组 `int map[5][4];` 来表⽰地图。已知 int 占 4 字节,如果 map 的内存地址是 0x2000,则表达式 `&map + 1` 的地址值是( )。
7. 执⾏完下⾯代码后,变量 val 的值是( )。 ```cpp int data[] = {10, 20, 30, 40, 50}; int *ptr = data + 2; int val = *(ptr - 1) + *(ptr + 1); ```
8. 某班 3 个⼩组、每组 4 名同学的分数存⼊下⾯的⼆维数组 score,则 `score[1][2]` 的值是( )。 ```cpp int score[3][4] = { {80, 81, 82, 83}, {90, 91, 92, 93}, {70, 71, 72, 73} }; ```
9. ⼩杨定义了⼀个结构体 Hero 来表⽰游戏⻆⾊,下⾯哪种初始化⽅式会由于语法错误导致编译失败?( )。 ```cpp struct Hero { string name; int hp; }; ```
10. 下⾯程序输出结果是( )。 ```cpp struct Book { string title; int pages; }; int main() { Book books[2] = {{"Math", 120}, {"Science", 150}}; cout << books[1].title; return 0; } ```
11. ⼩杨在对"能量晶⽯"按亮度进⾏排序。如果两块晶⽯亮度相同,他希望保持它们在原始序列中的相对顺序。下列关于排序算法稳定性的说法,错误的是( )。
12. ⼩杨的机器⼈正在能量踏板上跳跃,踏板编号为 1, 2, …。跳到第 $i$ 块踏板的⽅案数满⾜递推式 $f(n) = f(n-1) + f(n-2)$。若 $f(1) = 1, f(2) = 2$,则运⾏以下代码计算 `jump(5)` 的结果是( )。 ```cpp int jump(int n) { if (n <= 2) return n; int a = 1, b = 2, c = 0; for (int i = 3; i <= n; i++) { c = a + b; a = b; b = c; } return c; } ```
13. 在"模拟实验室"程序中,为了防⽌除以 0 导致崩溃,⼩杨使⽤了异常处理机制。执⾏以下代码将输出( )。 ```cpp try { int x = 10, y = 0; if (y == 0) throw "Zero Error"; cout << x / y; } catch (int e) { cout << "Error Code: " << e; } catch (const char* msg) { cout << "Caught: " << msg; } ```
14. 下⾯代码使⽤某种排序算法,将数组中的元素按从⼩到⼤排序。这段代码使⽤的排序算法是( )。 ```cpp void mystery_sort(double arr[], int n) { for (int i = 0; i < n - 1; i++) { int minPos = i; for (int j = i + 1; j < n; j++) { if (arr[j] < arr[minPos]) { minPos = j; } } double temp = arr[i]; arr[i] = arr[minPos]; arr[minPos] = temp; } } ```
15. ⼩杨正在读取"冒险⽇志"⽂件 quest.txt。若⽂件内容为 `Level 10`,执⾏以下程序后输出为( )。 ```cpp ifstream fin("quest.txt"); string s; int v; fin >> s >> v; cout << s.length() * v; ```

二、判断题(每题 2 分)

1. 运⾏以下程序后,变量 a 的值最终会变为 20。 ```cpp void modify(int *p) { *p = *p + 10; } int main() { int a = 10; modify(&a); return 0; } ```
2. 在 C++ 中,引⽤⼀旦初始化并绑定到某个变量后,可以通过赋值语句将其重新绑定到另⼀个变量。
3. 下⾯程序可以正确计算并输出 3 名学⽣的平均成绩。 ```cpp 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; } ```
4. 选择排序算法在寻找每⼀轮最⼩值时,如果遇到相等的元素不进⾏交换,则选择排序是⼀种稳定的排序算法。
5. 如果使⽤带 flag 的冒泡排序,且待排序数组⼀开始就是有序的,那么算法只需⼀轮扫描即可结束,时间复杂度为 $O(n)$。
6. 在 C++ 中定义⼆维数组并初始化时,可以省略第⼀维,但不能省略第⼆维。因此 `int a[][2] = {{1, 2}, {3, 4}};` 是合法的,⽽ `int a[][] = {{1, 2}, {3, 4}};` 是不合法的。
7. 下⾯代码的时间复杂度是 $O(n^2)$。 ```cpp int cnt = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { cnt++; } } ```
8. 假设⽂件 output.txt 能正常打开,下⾯代码通过 rdbuf 将 cout 的输出重定向到了⽂件中。 ```cpp ofstream fout("output.txt"); streambuf* old_buf = cout.rdbuf(); cout.rdbuf(fout.rdbuf()); cout << "GESP Exam"; cout.rdbuf(old_buf); ```
9. ⼩杨想通过下⾯程序给饭卡充值,程序会输出 70。 ```cpp void recharge(int money) { money += 20; } int main() { int card = 50; recharge(card); cout << card; return 0; } ```
10. 下⾯代码可以通过编译。 ```cpp int a[5]; a++; ```