GESP C++ 4级 2026.06
小杨正在编写一个 “数字交换器” 程序,他希望通过函数交换两个变量的值。请问运行以下代码后,屏幕上输出的是( )。
void exchange(int *a, int &b) {
int t = *a;
*a = b;
b = t;
}
int main() {
int x = 100, y = 200;
exchange(&x, y);
cout << x << " " << y;
return 0;
}
100 200
200 100
200 200
编译错误
下面程序想通过函数计算三门课总分,横线处应填入的是( )。
int sumScore(int a, int b, int c) {
return a + b + c;
}
int main() {
int chinese = 88, math = 95, english = 90;
int total = ______;
cout << total;
return 0;
}
sumScore
sumScore(chinese, math, english)
sumScore(int chinese, int math, int english)
sumScore(a, b, c)
以下程序的输出结果是( )。
int addOne(int x) {
return x + 1;
}
int main() {
int a = 6;
cout << addOne(a) + addOne(3);
return 0;
}
关于以下程序,说法正确的是( )。
void show() {
int stars = 5;
}
int main() {
cout << stars;
return 0;
}
程序输出
程序可以通过编译,但输出随机值
程序不能通过编译,因为 stars 只在 show 函数中有效
程序不能通过编译,因为 cout 不能输出变量
小杨在调试一个 “等级提升” 系统,代码逻辑如下,执行后 *p 的值是( )。
int lv = 5, next_lv = 6;
int *p = &lv;
*p = *p + 1;
p = &next_lv;
lv 的地址
next_lv 的地址
小杨正在开发一款名为“ 星际网格” 的游戏,他用二维数组 int map[5][4]; 来表示地图。已知 int 占 字节,如果 map 的内存地址是 0x2000 ,则表达式 &map + 1 的地址值是( )
0x204c
0x205c
0x2050
0x2058
执行完下面代码后,变量 val 的值是( )。
int data[] = {10, 20, 30, 40, 50};
int *ptr = data + 2;
int val = *(ptr - 1) + *(ptr + 1);
某班 个小组、每组 名同学的分数存入下面的二维数组 score ,则 score[1][2] 的值是( )。
int score[3][4] = {
{80, 81, 82, 83},
{90, 91, 92, 93},
{70, 71, 72, 73}
};
小杨定义了一个结构体 Hero 来表示游戏角色,下面哪种初始化方式会由于语法错误导致编译失败??( )
struct Hero {
string name;
int hp;
};
Hero h = {"Arthur", 100};
Hero h;
h.name = "Arthur";
h.hp = 100;
Hero h = new Hero{"Arthur", 100};
Hero *p = new Hero{"Arthur", 100};
下面程序输出结果是( )。
struct Book {
string title;
int pages;
};
int main() {
Book books[2] = {{"Math", 120}, {"Science", 150}};
cout << books[1].title;
return 0;
}
Math
Science
