#CIEXP263C3Z. C++Z3卷63
C++Z3卷63
C++Z3卷63
一、单选题(共10题)
1.以下关于 C++函数的说法,正确的是?{{ select(1) }}
- 函数必须有返回整数值,否则无法通过编译
- 函数可以嵌套定义,即在一个函数内部定义另一个函数
- 函数可以没有参数,也可以有多个参数
- 函数声明和函数定义必须写在同一个文件中
2.函数定义为 int func(int a, int b),以下调用方式正确的是?{{ select(2) }}
- func(5);
- func(5, 3);
- func("5", "3");
- int func(5,3);
3.以下函数,采用值传递方式的是?{{ select(3) }}
- void func(int &x)
- void func(int *x)
- void func(int x)
- void func(int x[])
4.执行以下代码,输出结果是?
#include <iostream>
void func(int x) {
x = 100;
}
int main() {
int a = 10;
func(a);
std::cout << a;
return 0;
}
{{ select(4) }}
- 10
- 100
- 0
- 编译报错
5.以下递归函数用于计算 n 的阶乘,横线处应填入的代码是?()
int fact(int n) {
if(n <= 1) return 1;
_________
}
{{ select(5) }}
- return fact(n-1);
- return n * fact(n-1);
- return n + fact(n-1);
- return fact(n) * fact(n-1);
6.以下哪个函数可以获取 C 风格字符串的长度?{{ select(6) }}
- strlen()
- strcpy()
- strcat()
- strcmp()
7.执行 strcmp("apple", "banana"),返回值的情况?{{ select(7) }}
- 大于 0
- 等于 0
- 小于 0
- 不确定
8.要找出 1000 以内所有不能被 7 整除且个位数位不为 7 的正数,最适合使用的算法?{{ select(8) }}
- 递归法
- 枚举法
- 分治法
- 动态规划
9.阅读以下程序,输入整数 60 时,程序的输出结果是?
#include<iostream>
int main() {
int n;
std::cin >> n;
for (int p = 2; p*p <= n; ++p) {
while (n % p == 0) {
n = n / p;
std::cout << p << " ";
}
}
if (n > 1)
std::cout << n;
}
{{ select(9) }}
- 2 2 3 5
- 2 3 5
- 2 3 3 60
- 2 5
10.以下代码用于统计 1~100 中,个位数字是 3 的数的个数,横线处应填入的代码是?
#include <iostream>
int main() {
int cnt = 0;
for(int i=1;i<=100;i++) {
if(_________)
cnt++;
}
std::cout << cnt;
}
{{ select(10) }}
- i % 3 == 0
- i / 10 == 3
- i % 10 == 3
- i / 3 == 0
二、判断题(共10题)
1.函数的返回值类型为 void 时,函数内不能使用 return 语句。{{ select(11) }}
- 正确
- 错误
2.C++中,函数支持重载,即同名函数可以有不同的参数列表。{{ select(12) }}
- 正确
- 错误
3.引用传递方式下,函数内对形参的修改会影响到实参。{{ select(13) }}
- 正确
- 错误
4.递归函数必须有明确的终止条件,否则会出现无限递归,导致栈溢出。{{ select(14) }}
- 正确
- 错误
5.递归算法的执行效率一定高于非递归算法。{{ select(15) }}
- 正确
- 错误
6.strcpy(a, b) 会将字符串 b 的内容复制到字符串 a 中,无需考虑 a 的空间大小。{{ select(16) }}
- 正确
- 错误
7.C 风格字符串以 '\0' 作为结束标志。{{ select(17) }}
- 正确
- 错误
8.枚举法的核心是遍历所有可能的情况,逐一验证是否符合条件。{{ select(18) }}
- 正确
- 错误
9.枚举法的时间复杂度通常很低,适用于所有数据范围的问题。{{ select(19) }}
- 正确
- 错误
10.模拟法是通过代码模拟问题的实际执行过程,从而得到结果。{{ select(20) }}
- 正确
- 错误