#GESP202512C4T2. 判断题(每题 2 分,共 20 分)
判断题(每题 2 分,共 20 分)
二、判断题
小杨正在调试他的温度传感器程序,其中变量 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 题 考虑用如下递推方式计算斐波那契数列,时间复杂度是 。
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) }}
- 对
- 错