CCF GESP 2026年6月认证 C++ 4级
二
判断题
第 1 题
运行以下程序后,变量
a 的值最终会变为 $20$。void modify(int *p) {
*p = *p + 10;
}
int main() {
int a = 10;
modify(&a);
return 0;
}
第 2 题
在
C++ 中,引用一旦初始化并绑定到某个变量后,可以通过赋值语句将其重新绑定到另一个变量。
第 3 题
下面程序可以正确计算并输出 $3$ 名学生的平均成绩。
struct Student {
int id;
int score;
};
int main() {
Student students[3] = {
{1, 90},
{2, 80},
{3, 100}
};
int sum = 0;
for (int i = 0; i < 3; i++) {
sum += students[i].score;
}
double average = sum / 3.0;
cout << average << endl;
return 0;
}
第 4 题
选择排序算法在寻找每一轮最小值时,如果遇到相等的元素不进行交换,则选择排序是一种稳定的排序算法。
第 5 题
如果使用带
flag 的冒泡排序,且待排序数组一开始就是有序的,那么算法只需一轮扫描即可结束,时间复杂度为 O(n)。
第 6 题
在
C++ 中定义二维数组并初始化时,可以省略第一维,但不能省略第二维。因此 int a[][2] = {{1, 2}, {3, 4}}; 是合法的,而 int a[][] = {{1, 2}, {3, 4}}; 是不合法的。
第 7 题
下面代码的时间复杂度是 $O(2^n)$。
int cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cnt++;
}
}
第 8 题
假设文件
output.txt 能正常打开,下面代码通过 rdbuf 将 cout 的输出重定向到了文件中。ofstream fout("output.txt");
streambuf* old_buf = cout.rdbuf();
cout.rdbuf(fout.rdbuf());
cout << "GESP Exam";
cout.rdbuf(old_buf);
第 9 题
小杨想通过下面程序给饭卡充值,程序会输出 $70$。
void recharge(int money) {
money += 20;
}
int main() {
int card = 50;
recharge(card);
cout << card;
return 0;
}
第 10 题
下面代码可以通过编译。
int a[5];
a++;
判断题部分已到底了。