#GESP202509C4T2. 判断题(每题 2 分,共 20 分)

判断题(每题 2 分,共 20 分)

二、判断题

第 16 题 以下代码能正确初始化指针。

int a = 5;
int *p = a;

{{ select(16) }}


第 17 题 执行下面 C++ 代码将输出 11 。

int x = 10;
void f() {
    int x = x + 1;
    cout << x << endl;
}
int main() {
    f();
}

{{ select(17) }}


第 18 题 以下 C++ 代码合法。

struct Student {
    string name;
    int age;
    float score;
};
Student* students = new Student[20];

{{ select(18) }}


第 19 题 执行下面 C++ 代码将输出 10 。

void func(int* p) {
    *p = 10;
}
int main() {
    int a = 5;
    func(&a);
    cout << a << endl;
    return 0;
}

{{ select(19) }}


第 20 题 下面代码将二维数组 arr 传递给函数 f ,函数内部用 arr[i][j] 访问元素,函数参数声明为 int arr[][4] 是错误的。

void f(int arr[][4], int rows) {
    // 访问 arr[i][j]
}
int main() {
    int arr[3][4] = { /* 初始化 */ };
    f(arr, 3);
}

{{ select(20) }}


第 21 题 递推是在给定初始条件下,已知前一项(或前几项)求后一项的过程。

{{ select(21) }}


第 22 题 虽然插入排序的时间复杂度为 O(n2)O(n^2) ,但由于单元操作相对较少,因此在小数据量的排序任务中非常受欢迎。

{{ select(22) }}


第 23 题 对整数数组 {4,1,3,1,5,2}\{4,1,3,1,5,2\} 进行冒泡排序(将最大元素放到最后),执行一轮之后是 {4,1,3,1,2,5}\{4,1,3,1,2,5\}

{{ select(23) }}


第 24 题 以下代码只能捕获 int 类型异常。

int main(){
    try{
        throw 42;
    } catch(...){
        cout << "Caught" << endl;
    }
    return 0;
}

{{ select(24) }}


第 25 题 以下代码将 Hello 写入文件 data.txt

ofstream file("data.txt");
cout << "Hello" << endl;
file.close();

{{ select(25) }}