跳到正文
OJ
佛大附属信奥
在线评测 · 分级学习
学习
题库
测验
提交
作业
留言
登录
菜单
学习
题库
测验
提交
作业
留言
登录
GESP C++ 四级 · 2026 年 3 月认证理论卷
登录
后作答才能记录成绩
一、单选题(每题 2 分)
1.
执行下面程序后,输出为( )。 ```cpp int f(int x = 2){ return x * 3; } int main(){ cout << f() << " " << f(4); } ```
A. 2 12
B. 6 12
C. 6 4
D. 12 6
2.
执行下面代码后,输出为( )。 ```cpp int main() { int a = 5; int* p = &a; int** q = &p; **q += 7; cout << a << " " << *p; } ```
A. 5 5
B. 12 12
C. 12 5
D. 5 12
3.
已知: ```cpp int a[3][4] = { {1,2,3,4}, {5,6,7,8}, {9,10,11,12} }; int (*p)[4] = a; ``` 则表达式 *(*(p + 2) + 1) 的值为( )。
A. 6
B. 10
C. 9
D. 11
4.
执行下面程序后,输出为( )。 ```cpp void fun(int a, int &b, int *c){ a += 1; b += 2; *c += 3; } int main(){ int x = 1, y = 1, z = 1; fun(x, y, &z); cout << x << " " << y << " " << z; } ```
A. 2 3 4
B. 1 3 4
C. 2 1 4
D. 1 1 1
5.
执行下面程序后输出为( )。 ```cpp int x = 3; void f(int& x){ x += 2; } int main(){ int x = 10; f(x); cout << x << " " << ::x; } ```
A. 12 3
B. 10 5
C. 12 5
D. 10 3
6.
下列关于结构体初始化的写法,正确的是( )。
A. ```cpp struct Point { int x, y; }; Point p = (1,2); ```
B. ```cpp struct Point { int x, y; }; Point p = {1,2}; ```
C. ```cpp struct Point { int x, y; }; Point p = new Point(1,2); ```
D. ```cpp struct Point { int x, y; }; Point p = <1,2>; ```
7.
执行下面代码后输出为( )。 ```cpp struct S { int a; int b; }; void g(S s){ s.a += 10; } void h(S& s){ s.b += 10; } int main(){ S s{1,2}; g(s); h(s); cout << s.a << " " << s.b; } ```
A. 11 12
B. 1 12
C. 11 2
D. 1 2
8.
关于递推算法的描述,正确的是( )。
A. 递推表现为函数自己调用自己
B. 递推从已知初值出发,利用递推关系逐步推出后续结果
C. 递推只能用于指数复杂度问题
D. 递推一定需要回溯
9.
执行 climb(6) 的返回值为( )。 ```cpp int climb(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; } ```
A. 8
B. 13
C. 5
D. 10
10.
某排序算法对如下数据排序(按 score 升序),则下面关于该排序算法稳定性的描述中,说法正确的是( )。 - 初始:(90,'A'), (90,'B'), (80,'C'), (90,'D') - 排序后:(80,'C'), (90,'A'), (90,'B'), (90,'D')
A. 不稳定,因为出现了相同分数
B. 稳定,因为相同 score 的相对顺序保持为 A 在 B 前、B 在 D 前
C. 不稳定,因为 C 跑到前面了
D. 无法判断
11.
下面代码试图把数组按升序进行"插入排序",横线处应填写( )。 ```cpp void ins(int a[], int n){ for(int i = 1; i < n; i++){ int key = a[i]; int j = i-1; while(j >= 0 && __________){ a[j+1] = a[j]; j--; } a[j+1] = key; } } ```
A. a[j] < key
B. a[j] > key
C. a[j+1] > key
D. a[j] == key
12.
下列代码段的时间复杂度为( )。 ```cpp int cnt=0; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if( (i+j) % 3 == 0) cnt++; } } ```
A. $O(n)$
B. $O(n \log n)$
C. $O(n^2)$
D. $O(2^n)$
13.
下面哪种方式不能实现将字符串 Welcome to 2026! 输出重定向到文件 log.txt( )。
A. ```cpp freopen("log.txt", "w", stdout); cout << "Welcome to 2026!" << endl; fclose(stdout); ```
B. ```cpp std::ofstream outFile("log.txt"); cout << "Welcome to 2026!" << endl; outFile.close(); ```
C. ```cpp ofstream log_file("log.txt"); streambuf* org_cout = cout.rdbuf(); cout.rdbuf(log_file.rdbuf()); cout << "Welcome to 2026!" << endl; cout.rdbuf(org_cout); ```
D. ```cpp std::ofstream outFile("log.txt"); outFile << "Welcome to 2026!" << endl; outFile.close(); ```
14.
执行下面程序,输出结果是( )。 ```cpp int divi(int a,int b){ if(b==0) throw 0; return a/b; } int main(){ try{ cout << divi(10,0); }catch(const char* msg){ cout << "A"; }catch(int){ cout << "B"; } } ```
A. A
B. B
C. 程序崩溃
D. 无输出
15.
下列函数实现排行榜中单个元素的位置调整(类似插入排序的相邻搬移)。当某玩家分数增加,需将其向前移动时,while 循环的条件应为( )。 ```cpp struct Player{ int score; }; void up(Player players[], int n, int idx){ Player cur = players[idx]; int i = idx; while( ____________________ ){ players[i] = players[i-1]; i--; } players[i] = cur; } ```
A. i > 0 && cur.score > players[i-1].score
B. i > 0 && cur.score < players[i-1].score
C. i < n-1 && cur.score > players[i+1].score
D. i < n-1 && cur.score < players[i+1].score
二、判断题(每题 2 分)
1.
下面代码执行结束时,变量 a 的值变成 15。 ```cpp void add10(int &x) { x += 10; } int main() { int a = 5; add10(a); } ``` ( )
对
错
2.
引用一旦绑定某个变量,就不能再绑定其他变量。( )
对
错
3.
执行下面代码,输出结果为 5。 ```cpp int main() { int a[2][3]; cout << &a[1][2] - &a[0][1] << endl; return 0; } ``` ( )
对
错
4.
下面程序可以正常编译并输出 10。 ```cpp 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); } ``` ( )
对
错
5.
下面程序执行后输出 2010。 ```cpp int x = 10; void f() { int x = 20; cout << x; } int main() { f(); cout << x; } ``` ( )
对
错
6.
在 C++ 中,如果声明了一个指针变量但没有显式初始化,该指针会自动被初始化为 nullptr。 ( )
对
错
7.
下面代码没有语法错误。 ```cpp 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; }; ``` ( )
对
错
8.
下面程序能够把 Hello 写入 data.txt 文件中。 ```cpp ofstream fout("data.txt"); cout << "Hello"; fout.close(); ``` ( )
对
错
9.
由于选择排序和插入排序的时间复杂度均为$O(n^2)$,在任何实际场景下两者的性能表现几乎相同,可以互相替代。 ( )
对
错
10.
下面用递推方式计算斐波那契数列第 n 项的程序,时间复杂度是$O(n)$。 ```cpp 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; } ``` ( )
对
错