当前位置:网站首页>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

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 :

  1. first line , Variable a Point to the first number of the array ;
  2. The second line , Variable p Point to the fifth number of the array (a + 4);
  3. 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 ,*p Get 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 .

原网站

版权声明
本文为[Fried fried dough sticks]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210826393724.html