#GESP202606C4T1. 单选题(每题 2 分,共 30 分)

单选题(每题 2 分,共 30 分)

  1.  \ 小杨正在编写一个“数字交换器”程序,他希望通过函数交换两个变量的值。请问运行以下代码后,屏幕上输出的是( )。
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;
}

{{ select(1) }}

  • 100100 200200
  • 200200 100100
  • 200200 200200
  • 编译错误

  1.  \ 下面程序想通过函数计算三门课总分,横线处应填入的是( )。
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;
}

{{ select(2) }}

  • sumScore
  • sumScore(chinese, math, english)
  • sumScore(int chinese, int math, int english)
  • sumScore(a, b, c)

  1.  \ 下面程序输出结果是( )。
int addOne(int x) {
    return x + 1;
}
int main() {
    int a = 6;
    cout << addOne(a) + addOne(3);
    return 0;
}

{{ select(3) }}

  • 99
  • 1010
  • 1111
  • 1212

  1.  \ 关于下面程序,说法正确的是( )。
void show() {
    int stars = 5;
}
int main() {
    cout << stars;
    return 0;
}

{{ select(4) }}

  • 程序输出 55
  • 程序可以通过编译,但输出随机值
  • 程序不能通过编译,因为 stars 只在 show 函数中有效
  • 程序不能通过编译,因为 cout 不能输出变量

  1.  \ 小杨在调试一个“等级提升”系统,代码逻辑如下,执行后 *p 的值是( )。
int lv = 5, next_lv = 6;
int *p = &lv;
*p = *p + 1;
p = &next_lv;

{{ select(5) }}

  • 55
  • 66
  • lv 的地址
  • next_lv 的地址

  1.  \ 小杨正在开发一款名为“星际网格”的游戏,他用二维数组 int map[5][4]; 来表示地图。已知 int44 字节,如果 map 的内存地址是 0x2000,则表达式 &map + 1 的地址值是( )。

{{ select(6) }}

  • 0x204c
  • 0x205c
  • 0x2050
  • 0x2058

  1.  \ 执行完下面代码后,变量 val 的值是( )。
int data[] = {10, 20, 30, 40, 50};
int *ptr = data + 2;
int val = *(ptr - 1) + *(ptr + 1);

{{ select(7) }}

  • 5050
  • 6060
  • 7070
  • 8080

  1.  \ 某班 33 个小组、每组 44 名同学的分数存入下面的二维数组 score,则 score[1][2] 的值是( )。
int score[3][4] = {
    {80, 81, 82, 83},
    {90, 91, 92, 93},
    {70, 71, 72, 73}
};

{{ select(8) }}

  • 8181
  • 9090
  • 9292
  • 7272

  1.  \ 小杨定义了一个结构体 Hero 来表示游戏角色,下面哪种初始化方式会由于语法错误导致编译失败?( )。
struct Hero {
    string name;
    int hp;
};

{{ select(9) }}

  • Hero h = {"Arthur", 100};
  • Hero h; h.name = "Arthur"; h.hp = 100;
  • Hero h = new Hero{"Arthur", 100};
  • Hero *p = new Hero{"Arthur", 100};

  1.  \ 下面程序输出结果是( )。
struct Book {
    string title;
    int pages;
};
int main() {
    Book books[2] = {{"Math", 120}, {"Science", 150}};
    cout << books[1].title;
    return 0;
}

{{ select(10) }}

  • Math
  • Science
  • 120120
  • 150150

  1.  \ 小杨在对“能量晶石”按亮度进行排序。如果两块晶石亮度相同,他希望保持它们在原始序列中的相对顺序。下列关于排序算法稳定性的说法,错误的是( )。

{{ select(11) }}

  • 冒泡排序是稳定的,因为只有在左边比右边大时才交换。
  • 插入排序是稳定的,因为它将元素插入到相等元素的右侧。
  • 选择排序是稳定的,因为它每次选出最小元素放在前面。
  • 稳定性是指排序后相等元素的相对位置不发生改变。

  1.  \ 小杨的机器人正在能量踏板上跳跃,踏板编号为 1,2,,n1,2,\ldots,n。跳到第 nn 块踏板的方案数满足递推式 f(n)=f(n1)+f(n2)f(n)=f(n-1)+f(n-2)。若 f(1)=1f(1)=1f(2)=2f(2)=2,则运行以下代码计算 jump(5) 的结果是( )。
int jump(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;
}

{{ select(12) }}

  • 55
  • 88
  • 1313
  • 2121

  1.  \ 在“模拟实验室”程序中,为了防止除以 00 导致崩溃,小杨使用了异常处理机制。执行以下代码将输出( )。
try {
    int x = 10, y = 0;
    if (y == 0) throw "Zero Error";
    cout << x / y;
} catch (int e) {
    cout << "Error Code: " << e;
} catch (const char* msg) {
    cout << "Caught: " << msg;
}

{{ select(13) }}

  • 00
  • Error Code: 0
  • Caught: Zero Error
  • 程序直接崩溃

  1.  \ 下面代码使用某种排序算法,将数组中的元素按从小到大排序。这段代码使用的排序算法是( )。
void mystery_sort(double arr[], int n) {
    for (int i = 0; i < n - 1; i++) {
        int minPos = i;
        for (int j = i + 1; j < n; j++) {
            if (arr[j] < arr[minPos]) {
                minPos = j;
            }
        }
        double temp = arr[i];
        arr[i] = arr[minPos];
        arr[minPos] = temp;
    }
}

{{ select(14) }}

  • 冒泡排序
  • 插入排序
  • 选择排序
  • 非典型排序

  1.  \ 小杨正在读取“冒险日志”文件 quest.txt。若文件内容为 Level 10,执行以下程序后输出为( )。
ifstream fin("quest.txt");
string s;
int v;
fin >> s >> v;
cout << s.length() * v;

{{ select(15) }}

  • 5050
  • 1515
  • 7070
  • 55