#G1052. GESP C++ 三级模拟试卷
GESP C++ 三级模拟试卷
1. 在8位二进制补码表示中,十进制数 的十六进制表示是({{ select(1) }} )。
FAFB0585
2. 执行以下C++代码段后,变量 c 的值是( )。
int a = 12;
int b = 5;
int c = (a ^ b) & (~b);
cout << c << endl;
{{ select(2) }}
- 5
- 7
- 8
- 12
3. 阅读下列代码,输出结果是( )。
int b[5] = {1, 2, 3, 4, 5};
int s = 0;
for(int i = 0; i < 4; i += 2) {
s += b[i] * b[i+1];
}
cout << s << endl;
{{ select(3) }}
- 10
- 14
- 15
- 20
4. 执行以下代码,输出结果是( )。
string s = "GESP2025";
int cnt = 0;
for (char c : s) {
if (c >= '0' && c <= '9') {
cnt += (c - '0');
}
}
cout << cnt << endl;
{{ select(4) }}
- 9
- 2025
- 14
- 0
5. 下列函数用于将十进制整数 n 转换为二进制并输出,横线处应填入( )。
void toBinary(int n) {
if (n == 0) return;
toBinary(n / 2);
________________;
}
{{ select(5) }}
cout << n % 2;cout << n / 2;cout << n % 10;cout << n << endl;
6. 执行以下代码,输出结果是( )。
int x = 10, y = 5;
if (x > 5 && y < 5 || x == 10) {
cout << "A";
} else {
cout << "B";
}
{{ select(6) }}
ABAB- 编译错误
7. 下列代码的功能是( )。
int a[10] = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3};
int maxVal = a[0];
for (int i = 1; i < 10; i++) {
if (a[i] > maxVal) maxVal = a[i];
}
cout << maxVal;
{{ select(7) }}
- 计算数组元素的和
- 查找数组中的最大值
- 统计数组中大于5的元素个数
- 将数组元素从小到大排序
8. 若要判断整数 n 是否为偶数,下列表达式正确的是( )。
{{ select(8) }}
(n & 1) == 1(n | 1) == 0(n & 1) == 0(n ^ 1) == 0
9. 执行以下代码,输出结果是( )。
string str = "Hello";
str.replace(1, 3, "aa");
cout << str << endl;
{{ select(9) }}
Haa oHaaloHaaelloHeaa o
10. 执行以下代码,count 的最终值是( )。
int count = 0;
for (int i = 1; i <= 20; i++) {
if (i % 3 == 0 && i % 5 != 0) {
count++;
}
}
cout << count << endl;
{{ select(10) }}
- 4
- 5
- 6
- 7
11. 在32位系统中,int 类型变量 a = -1,执行 unsigned int b = a; 后,b 的值是( )。
{{ select(11) }}
- -1
- 1
- 2147483647
- 4294967295
12. 下列代码输出结果是( )。
int a = 5, b = 3;
a = a ^ b;
b = a ^ b;
a = a ^ b;
cout << a << " " << b << endl;
{{ select(12) }}
- 5 3
- 3 5
- 6 6
- 0 0
13. 定义 int arr[5] = {1, 2, 3, 4, 5};,下列访问方式中,会导致越界访问的是( )。
{{ select(13) }}
arr[0]arr[4]arr[5]arr[2]
14. 小杨想找出100以内所有能被7整除但不能被3整除的数。下列条件判断正确的是( )。 {{ select(14) }}
if (i % 7 == 0 || i % 3 != 0)if (i % 7 == 0 && i % 3 == 0)if (i % 7 == 0 && i % 3 != 0)if (i % 21 == 0)
15. 执行以下代码,输出的 * 总数是( )。
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
cout << "*";
}
}
{{ select(15) }}
- 3
- 5
- 6
- 9
二、判断题(每题1分,共10分)
- ({{ select(16) }} )在C++中,字符常量
'0'和整数常量0的值是相同的。
- 正确
- 错误
- ({{ select(17) }} )数组
int a[10];的有效下标范围是 0 到 10。
- 正确
- 错误
- ( {{ select(18) }})位运算符
&的优先级低于逻辑运算符&&。
- 正确
- 错误
- ( {{ select(19) }})对于有符号整数,右移运算符
>>在执行时通常会保留符号位(算术右移)。
- 正确
- 错误
- ({{ select(20) }} )
string类型的变量可以使用+运算符进行字符串拼接。
- 正确
- 错误
- ({{ select(21) }} )表达式
(10.0 / 3) * 3的结果在计算机浮点数运算中一定严格等于10.0。
- 正确
- 错误
- ({{ select(22) }} )定义
char s[] = "ABC";,则数组s的长度为 3。
- 正确
- 错误
- ({{ select(23) }} )任何一个
for循环都可以改写为等价的while循环。
- 正确
- 错误
- ({{ select(24) }} )在C++中,
true转换为整数时值为 1,false转换为整数时值为 0。
- 正确
- 错误
- ({{ select(25) }} )在原码和反码表示法中,0 的表示形式都是唯一的。
- 正确
- 错误