#1062. GESP C++ 四 级 2026年6月真题 · 单选题

GESP C++ 四 级 2026年6月真题 · 单选题

GESP C++ 四 级 2026年6月真题(120 分钟,总分 100 分)

单选题(共 15 题,每题 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. 下面程序输出结果是(  )。

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占4字节,如果map的内存地址是0x2000,则表达式&map+1的地址值是(  )。

{{ select(6) }}

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

7. 执行完下面代码后,变量val的值是(  )。

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

{{ select(7) }}

  • 50
  • 60
  • 70
  • 80

8. 某班3个小组、每组4名同学的分数存入下面的二维数组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;
    h.name = "Arthur";
    h.hp = 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. 小杨的机器人正在能量踏板上跳跃,踏板编号为1,2,3.....n。跳到第n块踏板的方案数满足递推式f(n)=f(n-1)+f(n-2)。若f(1)=1,f(2)=2,则运行以下代码计算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. 在“模拟实验室”程序中,为了防止除以0导致崩溃,小杨使用了异常处理机制。执行以下代码将输出(  )。

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. 下面代码使用某种排序算法,将数组中的元素按从小到大排序。这段代码使用的排序算法是(  )。

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