#1063. GESP C++ 四 级 2026年3月真题 · 判断题

GESP C++ 四 级 2026年3月真题 · 判断题

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

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

1. 下面代码执行结束时,变量 a 的值变成 15。

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

{{ select(1) }}

  • 正确
  • 错误

2. 引用一旦绑定某个变量,就不能再绑定其他变量。( )

{{ select(2) }}

  • 正确
  • 错误

3. 执行下面代码,输出结果为 5。

int main() {
   int a[2][3];
   cout << &a[1][2] - &a[0][1] << endl;
   return 0;
}

{{ select(3) }}

  • 正确
  • 错误

4. 下面程序可以正常编译并输出 10。

int calc(int x, int y = 10);
int calc(int x) { return x * 2; }
int calc(int x, int y) { return x * y; }
int main() {
   cout << calc(5);
}

{{ select(4) }}

  • 正确
  • 错误

5. 下面程序执行后输出 2010。

int x = 10;
void f() { int x = 20; cout << x; }
int main() {
   f();
   cout << x;
}

{{ select(5) }}

  • 正确
  • 错误

6. 在 C++ 中,如果声明了一个指针变量但没有显式初始化,该指针会自动被初始化为 nullptr。

{{ select(6) }}

  • 正确
  • 错误

7. 下面代码没有语法错误。

struct GameCharacter {
   string name;
   int level;
   float position_x;
   float position_y;  
   
   struct Equipment {
       string weapon;
       int attack_bonus;
       int defense_bonus;
  } equipment;
   
   struct Skill {
       string name;
       int damage;
  } skills[8];
   int skill_count;
};

{{ select(7) }}

  • 正确
  • 错误

8. 下面程序能够把 Hello 写入 data.txt 文件中。

ofstream fout("data.txt");
cout << "Hello";
fout.close();

{{ select(8) }}

  • 正确
  • 错误

9. 由于选择排序和插入排序的时间复杂度均为 O(n2),在任何实际场景下两者的性能表现几乎相同,可以互相替代。

{{ select(9) }}

  • 正确
  • 错误

10. 下面用递推方式计算斐波那契数列第 n 项的程序,时间复杂度是 O(2n)。

int fib(int n) {
   if (n <= 1) return n;
   int f0 = 0, f1 = 1, cur = 0;
   for (int i = 2; i <= n; i++) {
       cur = f0 + f1;
       f0 = f1;
       f1 = cur;
   }
   return cur;
}

{{ select(10) }}

  • 正确
  • 错误