#1650. GESP-C++四级(2026-06)

GESP-C++四级(2026-06)

CCF GESP C++ 四级 (2026 年 06 月)

一、单选题(每题 2 分,共 30 分)

1. ⼩杨正在编写⼀个“数字交换器”程序,他希望通过函数交换两个变量的值。请问运⾏以下代码后,屏幕上输 出的是( )。

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;
}

{{ select(1) }}

  • 100 200
  • 200 100
  • 200 200
  • 编译错误

2. 下⾯程序想通过函数计算三门课总分,横线处应填⼊的是( )

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;
}

{{ select(2) }}

  • sumScore
  • sumScore(chinese, math, english)
  • sumScore(int chinese, int math, int english)
  • sumScore(a, b, c)

3. 下⾯程序输出结果是( )

/ 10
int addOne(int x) {
return x + 1;
}
int main() {
int a = 6;
cout << addOne(a) + addOne(3);
return 0;
}

{{ select(3) }}

  • 9
  • 10
  • 11
  • 12

4. 关于下⾯程序,说法正确的是( )

void show() {
int stars = 5;
}
int main() {
cout << stars;
return 0;
}

{{ select(4) }}

  • 程序输出 5
  • 程序可以通过编译,但输出随机值
  • 程序不能通过编译,因为 stars 只在 show 函数中有效
  • 程序不能通过编译,因为 cout 不能输出变量

5. ⼩杨在调试⼀个“等级提升”系统,代码逻辑如下,执⾏后 *p 的值是( )

int lv = 5, next_lv = 6;
int *p = &lv;
*p = *p + 1;
p = &next_lv;

{{ select(5) }}

  • 5
  • 6
  • lv 的地址
  • next_lv 的地址

6. ⼩杨正在开发⼀款名为“星际⽹格”的游戏,他⽤⼆维数组 int map[5][4]; 来表⽰地图。已知 int 占 字节,如果 map 的内存地址是 0x2000 ,则表达式 &map + 1 的地址值是( )。

{{ select(6) }}

  • 0x204c
  • 0x205c
  • 0x2050
  • 0x2058

7. 执⾏完下⾯代码后,变量 val 的值是( )

/ 10
int data[] = {10, 20, 30, 40, 50};
int *ptr = data + 2;
int val = *(ptr - 1) + *(ptr + 1);

{{ select(7) }}

  • 50
  • 60
  • 70
  • 80

8. 某班 个⼩组、每组 名同学的分数存⼊下⾯的⼆维数组 score ,则 score[1][2] 的值是( )

int score[3][4] = {
{80, 81, 82, 83},
{90, 91, 92, 93},
{70, 71, 72, 73}
};

{{ select(8) }}

  • 81
  • 90
  • 92
  • 72

9. ⼩杨定义了⼀个结构体 Hero 来表⽰游戏角⾊,下⾯哪种初始化⽅式会由于语法错误导致编译失败?( )。

struct Hero {
string name;
int hp;
};

{{ select(9) }}

  • Hero h = {"Arthur", 100};
  • Hero h = new Hero{"Arthur", 100};
  • Hero *p = new Hero{"Arthur", 100};

10. 下⾯程序输出结果是( )

struct Book {
string title;
int pages;
};
int main() {
Book books[2] = {{"Math", 120}, {"Science", 150}};
cout << books[1].title;
return 0;
}

{{ select(10) }}

  • Math
  • Science
  • 120
  • 150

11. ⼩杨在对“能量晶⽯”按亮度进⾏排序。如果两块晶⽯亮度相同,他希望保持它们在原始序列中的相对顺 序。下列关于排序算法稳定性的说法,错误的是( )。

{{ select(11) }}

  • 冒泡排序是稳定的,因为只有在左边⽐右边⼤时才交换。
  • 插⼊排序是稳定的,因为它将元素插⼊到相等元素的右侧。
  • 选择排序是稳定的,因为它每次选出最⼩元素放在前⾯。
  • 稳定性是指排序后相等元素的相对位置不发⽣改变。

12. ⼩杨的机器⼈正在能量踏板上跳跃,踏板编号为 。跳到第 块踏板的⽅案数满⾜递推式 。若 ,则运⾏以下代码计算 jump(5) 的结果是( )。

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;
}

{{ select(12) }}

  • 5
  • 8
  • 13
  • 21

13. 在“模拟实验室”程序中,为了防⽌除以 导致崩溃,⼩杨使⽤了异常处理机制。执⾏以下代码将输出( )。

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;
}

{{ select(13) }}

  • 0
  • Error Code: 0
  • Caught: Zero Error
  • 程序直接崩溃

14. 下⾯代码使⽤某种排序算法,将数组中的元素按从⼩到⼤排序。这段代码使⽤的排序算法是( )

/ 10
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;
}
}

{{ select(14) }}

  • 冒泡排序
  • 插⼊排序
  • 选择排序
  • ⾮典型排序

15. ⼩杨正在读取“冒险⽇志”⽂件 quest.txt 。若⽂件内容为 Level 10 ,执⾏以下程序后输出为( )

ifstream fin("quest.txt");
string s;
int v;
fin >> s >> v;
cout << s.length() * v;

{{ select(15) }}

  • 50
  • 15
  • 70
  • 5

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

1. 运⾏以下程序后,变量 a 的值最终会变为 20

{{ select(16) }}

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

{{ select(17) }}

3. 下⾯程序可以正确计算并输出 名学⽣的平均成绩 5 12

{{ select(18) }}

4. 选择排序算法在寻找每⼀轮最⼩值时,如果遇到相等的元素不进⾏交换,则选择排序是⼀种稳定的排序算 法。

{{ select(19) }}

5. 如果使⽤带 flag 的冒泡排序,且待排序数组⼀开始就是有序的,那么算法只需⼀轮扫描即可结束,时间 复杂度为 。

{{ select(20) }}

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

{{ select(21) }}

7. 下⾯代码的时间复杂度是

{{ select(22) }}

8. 假设⽂件 output.txt 能正常打开,下⾯代码通过 rdbuf 将 cout 的输出重定向到了⽂件中

{{ select(23) }}

9. ⼩杨想通过下⾯程序给饭卡充值,程序会输出 70

{{ select(24) }}

10. 下⾯代码可以通过编译

{{ select(25) }}