#5234. [GESP202512四级]模拟测试二-客观题
[GESP202512四级]模拟测试二-客观题
一.单选题(每题2分,共30分)
- 下列代码中,输出结果是( )。

{{ select(1) }}
12 24 24 1224 12 12 2412 12 24 2424 24 12 12
- 下面函数不能正常执行的是 ( )。
{{ select(2) }}
-
下面程序输出的是( )。

{{ select(3) }}
2 2 3 92 10 3 92 10 11 1212 10 3 100
- 下面这段代码会输出 ( )
01 int add(int a, int b = 1); // 函数声明
02
03 int main() {
04 cout << add(2) << " " << add(2, 3);
05 return 0;
06 }
07
08 int add(int a, int b) { // 函数定义
09 return a + b;
10 }
{{ select(4) }}
3 5- 编译失败:定义处少了默认参数
- 运行错误
- 链接失败:未定义引用
- 下面这段代码会输出 ( )
01 int x = 5;
02
03 void foo() {
04 int x = 10;
05 cout << x << " ";
06 }
07
08 void bar() {
09 cout << x << " ";
10 }
11
12 int main() {
13 foo();
14 bar();
15 }
{{ select(5) }}
5 510 105 1010 5
- 下面程序运行的结果是 ( )
01 void increaseA(int x) {
02 x++;
03 }
04 void increaseB(int* p) {
05 (*p)++;
06 }
07 int main() {
08 int a = 5;
09 increaseA(a);
10 cout << a << " ";
11 increaseB(&a);
12 cout << a;
13 }
{{ select(6) }}
6 76 65 65 5
- 下面C++代码执行以后输出的是( )。

{{ select(7) }}
016- 不确定
- 下面C++函数中采用的算法是( )

{{ select(8) }}
- 递推
- 递归
- 迭代
- 循环
- 插入排序在最好情况下的时间复杂度是( )。
{{ select(9) }}
- 下面代码试图实现选择排序,使其能对数组
nums排序为升序,则横线上应分别填写 ( )
01 void selectionSort(vector<int>& nums) {
02 int n = nums.size();
03 for (int i = 0; i < n - 1; ++i) {
04 int minIndex = i;
05 for (int j = i + 1; j < n; ++j) {
06 if ( __________ ) { // 在此处填入代码
07 minIndex = j;
08 }
09 }
10 ____________________; // 在此处填入代码
11 }
12 }
{{ select(10) }}
-
01 nums[j] < nums[minIndex] 02 swap(nums[i], nums[minIndex]) -
01 nums[j] > nums[minIndex] 02 swap(nums[i], nums[minIndex]) -
01 nums[j] <= nums[minIndex] 02 swap(nums[j], nums[minIndex]) -
01 nums[j] <= nums[minIndex] 02 swap(nums[i], nums[j])
- 给定如下算法,其时间复杂度为( )
01 bool f(int arr[], int n, int target) {
02 for (int i = 0; i < n; i++) {
03 int sum = 0;
04 for (int j = 0; j < n; j++) {
05 if (i & (1 << j)) {
06 sum += arr[j];
07 }
08 }
09 if (sum == target) return true;
10 }
11 return false;
12 }
{{ select(11) }}
- 下述斐波那契数列计算的时间复杂度是( )
01 int fibonacci(int n) {
02 if (n == 0) return 0;
03 if (n == 1) return 1;
04 return fibonacci(n - 1) + fibonacci(n - 2);
05 }
{{ select(12) }}
- 关于下面
C++程序的描述 ( ) 最准确。
01 ifstream in("data.txt");
02 string line;
03 while (getline(in, line)) {
04 cout << line << endl;
05 }
{{ select(13) }}
- 将从标准输入读取每行,并输出到屏幕
- 程序无法运行,因为
getline只能读取cin - 将
data.txt中的每一行读取并输出到屏幕 - 程序将创建
data.txt并写入默认文本
- 在
C++中,异常处理机制(try-catch块)的主要目的是 ( )
{{ select(14) }}
- 提高程序的运行速度
- 在程序发生运行时错误时,提供一种结构化的错误处理方式
- 确保程序在编译时没有错误
- 减少程序的内存占用
- 关于异常处理,以下说法错误的是 ( )
{{ select(15) }}
try块中的代码可能会抛出异常catch块可以有多个,处理不同类型的异常throw语句用于抛出异常- 所有异常都必须被捕获,否则程序会崩溃
二.判断题(每题2分,共20分)
- int& a 和 &a 是一样的,都是取 a 的地址。
{{ select(16) }}
- 正确
- 错误
- 以下代码不能够正确执行。

{{ select(17) }}
- 正确
- 错误
- 定义变量
int a=5, 则cout << &++a会输出 6 。( )
{{ select(18) }}
- 正确
- 错误
- 两个函数之间可以使用全局变量来传递数据。( )
{{ select(19) }}
- 正确
- 错误
- 定义数组
int a[2024][3][16]={2,0,2,4,3,1,6},则cout << a[2023][2][15]的结果不确定。( )
{{ select(20) }}
- 正确
- 错误
- 递推是在给定初始条件下,已知前一项 (或前几项) 求后一项的过程。
{{ select(21) }}
- 正确
- 错误
- 虽然插入排序的时间复杂度为 ,但由于单元操作相对较少,因此在小数据量的排序任务中非常受欢迎。
{{ select(22) }}
- 正确
- 错误
- 对整数数组
{4, 1, 3, 1, 5, 2}进行冒泡排序 (将最大元素放到最后),执行一轮之后是{4, 1, 3, 1, 2, 5}。
{{ select(23) }}
- 正确
- 错误
- 如果一个异常在 块中抛出但没有任何 匹配,它将在编译时报错。
{{ select(24) }}
- 正确
- 错误
- 下面
C++代码实现将 写入 。
01 ofstream out("data.txt");
02 out << "Hello";
03 out.close();
{{ select(25) }}
- 正确
- 错误
相关
在下列比赛中:



