当前位置:网站首页>MOOC course of Nanjing University of Technology: Fundamentals of program design (Ⅰ) Chapter 8 answer and analysis of multiple choice test questions
MOOC course of Nanjing University of Technology: Fundamentals of program design (Ⅰ) Chapter 8 answer and analysis of multiple choice test questions
2022-06-21 08:50:00 【Fried fried dough sticks】
List of articles
subject
The first question is
After executing the following code snippet ,b The value of is ________.
int a[] = {1,2,3,4,5,6,7,8};
int * p = a + 4;
int b = 4+ ++*p++;
A. 9
B. 8
C. Grammar mistakes
D. 10
answer :D
analysis :
- first line , Variable a Point to the first number of the array ;
- The second line , Variable p Point to the fifth number of the array (a + 4);
- The third line , because “( Left )
++” The operator of takes precedence over “*”, So go ahead++p, here , Variable p Point to the sixth number of the array ; next ,*pGet the number of corresponding addresses (6); Last , b = 4 + 6 = 10 b=4+6=10 b=4+6=10, So choose D(( Right )++On the variable b Execute after assignment , Yes b No influence ).
The second question is
The execution result of the following procedure is :
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
answer :D
analysis : function f3 It is to add parameters automatically , For arguments a There is no effect .
Third question
If there is a statement int a, *(*fun)(int *); fun Express ____
A. Pointer to function , This function returns int;
B. A function name , This function returns int;
C. Pointer to function , This function returns int*;
D. A function name , This function returns int*;
answer :C
analysis : Variable a It's useless , Therefore, the source code is simplified to int *(*fun)(int *);, Obviously, the return value type is int*,(*fun) Express fun function , Therefore, the following parentheses represent the formal parameter data type , Obviously int*.
Fourth question
Suppose there are the following statements :
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}};
Which of the following calls is illegal ?
A. f3(&a);
B. f3(&b[1]);
C. f3(b);
D. f3(b[1]);
answer :D
analysis : Pointer progression is different .
Fifth question
The following statement is provided :
char *s1 = "C++ Programming";
char s2[]= "C++ Programming";
Which of the following does not cause an error ?
A. strcpy(s2, "Java Programming");
B. strcpy(s1, "C++");
C. s1 = "C++";
D. s2 = s1;
answer :C
analysis : Options A, The string length exceeds the preset character array length when initializing the character array , Incorrect ; Options B,char *s1 Implication “ Constant string ” The meaning of , Can't change , Incorrect ; Options C, take s Pointer to string "C++", legal , correct ; Options D, Obviously not .
Sixth question
Equipped with int b[3][5]; Which of the following statements is correct ?
A. (int *)p[5] = b;
B. int *p[5] = b;
C. int (*p)[5] = b;
D. int *p[] = b;
answer :C
analysis : obviously .
Question seven
The following statement is provided :
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]};
Which of the following calls is legal ?
A. f4(b);
B. f4(&a);
C. f4(q);
D. f4(a);
answer :C
analysis : obviously .
The eighth question
The following sentences are provided :
char *c1[] = {"Red","Green","Blue"};
char c2[][6] = {"Red","Green","Blue"};
32 Which of the following statements in the bit system is correct ?
A. sizeof(c1) Add 4 be equal to sizeof(c2)
B. sizeof(c1) Add 6 be equal to sizeof(c2)
C. sizeof(c1) Greater than sizeof(c2)
D. sizeof(c1) be equal to sizeof(c2)
answer :B
analysis :c1 It's an array of pointers ,32 Bit pointer is 4 Bytes ;c2 Is a two-dimensional array , The second dimension is fixed 6 Bytes . therefore sizeof(c1)=3*4=12,sizeof(c2)=3*6=18.c2[][6] Fixed distribution 6 Bytes , Regardless of initialization , The compiler does .
remarks : If you want to in 64 Carry out under the machine 32 Bit compilation , You can refer to This blog
Question 9
There are sentences :int k=2, *intp = &k; So the expression :
(*fun)(*intp);
yes :
A. Bad expression .
B. Describe a function pointer fun.
C. Through function pointers fun To call a function , The argument is *intp.
D. take int Variable k Convert to pointer type fun.
answer :C
analysis : obviously
Question 10
Which of the following initializations is correct ?
A. int k, &p = &k;
B. float f; int *p = &f;
C. int *p = 0x3000
D. int k, *p = &k;
answer :D
analysis : obviously .
Eleventh questions
The execution output of the following code segment is ________.
int a = 2, *pa = &a;
int b = 3, *pb = &b;
*pa *=*pa**pb;
cout<<a<<endl;
A. 6
B. Grammar mistakes
C. 2
D. 12
answer :D
analysis : First, add the equivalent space to the program on the third line , Increase its readability *pa *= *pa * *pb;, obviously , It is equivalent to a = a * a * b = 2 * 2 * 3 = 12, So choose D.
Twelfth questions
What is correct in the following statement is :
A. int a,&ra=a,&&ref=ra;
B. int &refa[10];
C. int a,&ra=a,&*refp=&ra;
D. int *pi,*&pref=pi;
answer :D
analysis : obviously .
Thirteenth questions
int a[] = {1,2,3,4,5,6,7,8};
int * p = a + 4;
int b = 4+ ++*p++;
*p The value of is _____.
A. 4
B. 5
C. 6
D. 7
answer :C
analysis : Refer to the analysis of the first question .
Fourteenth questions
Hypothetical statements :
struct Person {
string name;
Person *father;
};
Person p1{ "tom" }, p2{"jerry", &p1}, *p = &p2;
Which of the following expressions has a value other than "tom".
A. p2.father->name
B. p->father->name
C. p1.name
D. p->name
answer :D
analysis : obviously
Question 15
There are sentences int b[3][4]; Which of the following statements is correct ?
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;
answer :B
analysis : obviously .
Sixteen
Which of the following main The function prototype is wrong ?
A. main(int arc, char **arv)
B. main(int argv, char *argc[])
C. main(int a, char *c[])
D. main(int argc, char *argv)
answer :C
analysis : obviously .
边栏推荐
- 一条命令开启监控之旅!
- Classic topics of leetcode array (I)
- Unity 5 自帶的Mono也可以支持C# 6
- Understanding and use of advanced pointer
- Reading method (three times reading method)
- Android database upgrade
- Using the method of combining shapes in illustrator
- C # implement callback
- Represent each record in the dataframe as a dictionary
- Abstractqueuedsynchronizer (AQS) source code detailed analysis - condition queue process analysis
猜你喜欢

Storage of floating point numbers in C language in memory

The next stop of Intelligent Manufacturing: cloud native + edge computing two wheel drive

TiDB3.0- 4.0 内存控制/修改日志保存天数/最大索引长度

What should I do if a white page appears during MySQL installation

Introduction to testing - Software Test Model

【VS】【使用问题】【解决方案】VS2010打开一直停留在启动界面

应用配置管理,基础原理分析

adb使用技巧和usb通信原理

The skill of using ADB and the principle of USB communication

Tsinghua University | van: visual attention network
随机推荐
The next stop of Intelligent Manufacturing: cloud native + edge computing two wheel drive
Classic topics of leetcode array (I)
TiDB、mysql修改系统变量/常用语句(杀死process中的进程)
C # implement callback
Idea common code templates
4.9 commander. js
客户端建设及调优实践
leetcode:19. 删除链表的倒数第 N 个结点
Give two strings S and T, and judge whether T is the word formed after rearrangement of S
在使用各种软件时 积累的快捷键
Retrofit extended reading
如何使用 adb shell 查询进程流量情况
Thread pool source code analysis_ 01 futuretask source code analysis
SQL to check the disk usage of the database / table, kill the process and terminate the connection in tidb
Detailed analysis of ThreadPoolExecutor source code of thread pool
Adapt to the pits in Huawei models
Mono of unity 5 can also support C # 6
JUnit中的@Transactional消失不见,@Rollback是否能单抗测试回滚的大旗?
Improve code checking with annotations
finally block can not complete normally