当前位置:网站首页>南京理工大学MOOC慕课:程序设计基础(Ⅰ)第8章测试选择题答案及解析
南京理工大学MOOC慕课:程序设计基础(Ⅰ)第8章测试选择题答案及解析
2022-06-21 08:26:00 【油条生煎】
题目
第一题
执行下面代码段后,b 的值为________。
int a[] = {1,2,3,4,5,6,7,8};
int * p = a + 4;
int b = 4+ ++*p++;
A. 9
B. 8
C. 语法错误
D. 10
答案:D
解析:
- 第一行,变量 a 指向数组第一个数;
- 第二行,变量 p 指向数组第五个数(a + 4);
- 第三行,由于“(左)
++”的运算符优先级高于“*”,故先进行++p,此时,变量 p 指向数组第六个数;接着,*p取对应地址的数(6);最后, b = 4 + 6 = 10 b=4+6=10 b=4+6=10,故选 D((右)++在对变量 b 赋值后执行,对 b 无影响)。
第二题
以下程序的执行结果是:
using namespace std;
#inlcude <iostream>
void f1(int *x){++*x;}
void f2(int &x){x++;}
void f3(int x){++x;}
int main(){
int a=10;
f1(&a); f2(a); f3(a);
cout<<a;
return 0;
}
A. 11
B. 13
C. 10
D. 12
答案:D
解析:函数 f3 是对形参进行自增,对实参 a 没有任何影响。
第三题
若有语句 int a, *(*fun)(int *); fun表示____
A. 指向函数的指针,该函数返回int;
B. 一个函数名,该函数返回int;
C. 指向函数的指针,该函数返回int*;
D. 一个函数名,该函数返回int*;
答案:C
解析:变量 a 无用,故将源代码简化为 int *(*fun)(int *);,显然返回值类型为 int*,(*fun) 表示 fun 函数,故其后面括号内即代表形参数据类型,显然为 int*。
第四题
假设有语句如下:
void f3(int (*p)[4]);
int a[4] = {1,2,3,4};
int b[3][4] = { {1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
下面哪一个调用是非法的?
A. f3(&a);
B. f3(&b[1]);
C. f3(b);
D. f3(b[1]);
答案:D
解析:指针级数不相同。
第五题
设有下面语句:
char *s1 = "C++ Programming";
char s2[]= "C++ Programming";
下面哪一种操作不会导致错误?
A. strcpy(s2, "Java Programming");
B. strcpy(s1, "C++");
C. s1 = "C++";
D. s2 = s1;
答案:C
解析:选项 A,字符串长度超出字符数组初始化时预设的字符数组长度,不正确;选项 B,char *s1 隐含“常量字符串”之意,无法改变,不正确;选项 C,将 s 指针指向字符串 "C++",合法,正确;选项 D,显然不正确。
第六题
设有 int b[3][5]; 下面哪一条语句是正确的?
A. (int *)p[5] = b;
B. int *p[5] = b;
C. int (*p)[5] = b;
D. int *p[] = b;
答案:C
解析:显然。
第七题
设有下面语句:
void f4(int **p);
int a[4] = {1,2,3,4};
int b[3][4] = {
{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
int *q[3] = {b[0],b[1],b[2]};
下面哪个调用是合法的?
A. f4(b);
B. f4(&a);
C. f4(q);
D. f4(a);
答案:C
解析:显然。
第八题
设有语句如下:
char *c1[] = {"Red","Green","Blue"};
char c2[][6] = {"Red","Green","Blue"};
32 位系统中下面哪一种说法是正确的?
A. sizeof(c1)加4 等于sizeof(c2)
B. sizeof(c1)加6 等于sizeof(c2)
C. sizeof(c1)大于sizeof(c2)
D. sizeof(c1)等于sizeof(c2)
答案:B
解析:c1 是指针数组,32位指针是4个字节;c2 是二维数组,第二维固定是6个字节。所以 sizeof(c1)=3*4=12,sizeof(c2)=3*6=18。c2[][6]固定分配6个字节,不管初始化,编译器做的。
备注:若想在64位机器下进行32位的编译,可以参考此博客
第九题
设有语句:int k=2, *intp = &k; 那么表达式:
(*fun)(*intp);
是:
A. 错误表达式。
B. 说明一个函数指针fun。
C. 通过函数指针fun 来调用函数,实参为*intp。
D. 将int 变量k 转换为指针类型fun。
答案:C
解析:显然
第十题
下面哪一个初始化是正确的?
A. int k, &p = &k;
B. float f; int *p = &f;
C. int *p = 0x3000
D. int k, *p = &k;
答案:D
解析:显然。
第十一题
下面代码段执行输出结果为________。
int a = 2, *pa = &a;
int b = 3, *pb = &b;
*pa *=*pa**pb;
cout<<a<<endl;
A. 6
B. 语法错误
C. 2
D. 12
答案:D
解析:先将第三行的程序加上等效的空格,增加其可读性 *pa *= *pa * *pb;,显然,其等价于 a = a * a * b = 2 * 2 * 3 = 12,故选 D。
第十二题
以下说明语句中正确的是:
A. int a,&ra=a,&&ref=ra;
B. int &refa[10];
C. int a,&ra=a,&*refp=&ra;
D. int *pi,*&pref=pi;
答案:D
解析:显然。
第十三题
int a[] = {1,2,3,4,5,6,7,8};
int * p = a + 4;
int b = 4+ ++*p++;
*p 的值为_____。
A. 4
B. 5
C. 6
D. 7
答案:C
解析:参考第一题的解析。
第十四题
假设语句:
struct Person {
string name;
Person *father;
};
Person p1{ "tom" }, p2{"jerry", &p1}, *p = &p2;
下面哪一个表达式的值不是"tom"。
A. p2.father->name
B. p->father->name
C. p1.name
D. p->name
答案:D
解析:显然
第十五题
设有语句 int b[3][4]; 下面哪一条语句是正确的?
A. int *p[2] = {b[0], b[1], b[2]};
B. int *p[] = {b[0], b[1], b[2]};
C. int *p[] = (int *[])b;
D. int *p[] = b;
答案:B
解析:显然。
第十六题
下列哪一个main 函数原型是错误的?
A. main(int arc, char **arv)
B. main(int argv, char *argc[])
C. main(int a, char *c[])
D. main(int argc, char *argv)
答案:C
解析:显然。
边栏推荐
- Global and Chinese market for online automatic optical inspection 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of electrical connectors 2022-2028: Research Report on technology, participants, trends, market size and share
- [DB written interview 225] in Oracle, if the online redo log file is damaged, how to recover it?
- Gql+nodejs+mysql database
- LeetCode数组经典题目(一)
- WordPress media library supports uploading and previewing SVG icons
- 1006 sign in and sign out (25 points)
- Antique typesetting (20 points) (test point 4)
- 面试经验---字节
- Redis master-slave vulnerability and remote connection vulnerability
猜你喜欢

Tsinghua University | van: visual attention network

解密FTP

window10局域网共享文件夹流程

Yunkang group passed the hearing: the revenue exceeded 1billion in 8 months and the profit within the period was 270Million

The market value of Jinshan office fell below 100 billion yuan: the shareholder Qiwen n-dimensional cash out exceeded 1.2 billion yuan

Visual studio code annotation plug-in: korofileheader

日记(C语言总结)

FD:文件描述符

Summary of problems and errors encountered in tidb4.0.0 (tiup deployment)

Three ways to solve cross domain problems
随机推荐
Kotlin---- control statement
WordPress obtains category name and link through category ID
Is it safe to open a stock account at present? Can I open an account online directly?
Complex four operations (23 lines of concise code)
安装MySQL出现白页面怎么办
4.9 commander. js
[yuanuniverse 3D competition]
Summary of problems and errors encountered in tidb4.0.0 (tiup deployment)
php exec、 system 、shell_ Exec cannot be executed. There is no result. The result is nulld. Solution
Nodejs post request JSON type and form type
Tsinghua University | van: visual attention network
Summary of mobile application development
Journal (résumé en langue c)
解密FTP
4.4 Eval function replaces function
Eureka的TimedSupervisorTask类(自动调节间隔的周期性任务)
The market value of Jinshan office fell below 100 billion yuan: the shareholder Qiwen n-dimensional cash out exceeded 1.2 billion yuan
Unity开发相关的博客收集
Unity's network request_ Short connection
2022-2028 global cooling on-off valve industry research and trend analysis report