#1060. GESP C++ 四 级 2025年12月真题 · 判断题

GESP C++ 四 级 2025年12月真题 · 判断题

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

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

1. 小杨正在调试他的温度传感器程序,其中变量x保存当前温度。下面这段代码运行后,变量x的值变成了8。

int x = 5;
int *p = &x;
*p = *p + 3;

{{ select(1) }}

  • 正确
  • 错误

2. 一个结构体不能包含另一个结构体。

{{ select(2) }}

  • 正确
  • 错误

3. 在C++中,定义如下二维数组:int a[3][4];,数组a在内存中是按行优先连续存放的,即a[0][0]、a[0][1]、a[0][2]、a[0][3]在内存中是连续的。

{{ select(3) }}

  • 正确
  • 错误

4. 执行下面程序后,变量a的值会变成15。

void add(int &x){
    x += 10;
}
int a = 5;
add(a);

{{ select(4) }}

  • 正确
  • 错误

5. 执行下面的C++代码,会输出8,因为两个指针地址相差8个字节(假设int占4字节)。

int arr[5] = {1, 2, 3, 4, 5};
int* p1 = arr;
int* p2 = arr + 2;
cout << p2 - p1;  // 输出结果

{{ select(5) }}

  • 正确
  • 错误

6. 考虑用如下递推方式计算斐波那契数列,时间复杂度是O(n)。

int n = 10;
int f[20];
f[0] = 0;
f[1] = 1;
for (int i = 2; i <= n; i++)
    f[i] = f[i - 1] + f[i - 2];

{{ select(6) }}

  • 正确
  • 错误

7. 冒泡排序和插入排序都是稳定排序算法。

{{ select(7) }}

  • 正确
  • 错误

8. 下面这段代码实现了选择排序算法。

void sort(int a[], int n) {
   for (int i = 1; i < n; i++) {
       int x = a[i];
       int j = i - 1;
       while (j >= 0 && a[j] > x) {
           a[j + 1] = a[j];
           j--;
      }
      a[j + 1] = x;
  }
}

{{ select(8) }}

  • 正确
  • 错误

9. 下面代码可以正常编译并输出10。

#include <iostream>
using namespace std;
int calculate(int x, int y = 10);
int main() {
   cout << calculate(5);  // 调用1
   return 0;
}
int calculate(int x, int y) {
   return x * y;
}
int calculate(int x) {  // 重载函数
   return x * 2;
}

{{ select(9) }}

  • 正确
  • 错误

10. 执行下面代码会输出100。

int main() {
   ofstream fout("data.txt");
   fout << 10 << " " << 20 << endl;
   fout << 30 << " " << 40;
   fout.close();
   ifstream fin("data.txt");
   int a, b, c, d;
   fin >> a >> b >> c >> d;
   fin.close();
   cout << a + b + c + d;
   return 0;
}

{{ select(10) }}

  • 正确
  • 错误