c ++ Test first week

The score: 14.00 / 14.00 , this test submission time: 2020-03-08 , if you think this test result is not satisfactory, you can chooseDo it again.

1
Radio (1 min)

The following program fragment which is right?

 

  • A.

    int n = 4;

    int & r = n * 5;

     

  • B.

    int n = 6;

    const int & r = n;

    r = 7;

     

  • C.

     

    int n = 8;

    const int & r1 = n;

    int & r2 = r1;

     

  • D.

    int n = 8;

    int & r1 = n;

    const int r2 = r1;

     

    1.00/1.00
2
Radio (1 min)

What output is the following program fragment?

 

int a = 1,b = 2;

int & r = a;

r = b;

r = 7;

cout << a << endl;

 

  • A.

    1

  • B.

    2

  • C.

    7

    1.00/1.00
  • D.

    8

3
Radio (1 min)

Which of the following statements is correct?

  • A.

    Often cited reference variable which can not be modified

  • B.

    Can not be constant pointer, which points to modify variables

    1.00/1.00
  • C.

    Once a constant pointer pointing to a variable, you can not point to other variables

  • D.

    1+1 = 3

4
Radio (1 min)

The expression "new int" return value type is:

  • A.

    int

  • B.

    int *

    1.00/1.00
  • C.

    int &

  • D.

    void

5
Radio (1 min)

The following subparagraph program, which is correct:

  • A.

       char * p = new char[10];       

       p[0] = 'K'; 

       delete [] p;

     

    1.00/1.00
  • B.

       int *p = new int[25]; 

       p[10] = 100; 

       delete p

     

  • C.

       char * p = new int; 

       p = 'a';  

       delete p;

     

  • D.

    int * p = new char[20]; 

6
Radio (1 min)

The following statement is correct:

  • A.

    The number of parameters of a plurality of overloaded functions must be different.

  • B.

    Two functions, identical parameter table, different types of return value, which relation is overloaded.

  • C.

    When you call a second and third parameters have default values ​​have a function, you can not write the second argument and write the third argument.

  • D.

    The purpose is to increase the inline function of running speed.

    1.00/1.00
  • Fill in the blank (2 points) simply swap by code is  (please refer to the announcement, "Note on programming operations" to complete the programming operation (Please note that programming questions are asked to submit by code, submitted a program on openjudge and later through it It can be downloaded through the code.)

      Total time limit: 1000ms Memory Limit: 65536kB    

           Description: fill in the blank, so that the program output is: 5,3

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    #include <iostream>
    using  namespace  std;
    class  A
    {
         public :
         int  x;
         int  getX() {  return  x; }   
    };
    void  swap(
    // 在此处补充你的代码
    )
    {
         int   tmp = a.x;
         a.x = b.x;
         b.x = tmp;
    }
    int  main()
    {
         A a,b;
         a.x = 3;
         b.x = 5;
         swap(a,b);
         cout << a.getX() <<  ","  << b.getX();
         return  0;
    }

      Input None Output 5,3

      answer:

    Fill in the blanks (2 points) little difficult swap

      Fill in the blank, so that the program output is: 5,3

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    #include <iostream>
    using  namespace  std;
     
    void  swap(
    // 在此处补充你的代码
    )
    {
         int  * tmp = a;
         a = b;
         b = tmp;
    }
    int  main()
    {
         int  a = 3,b = 5;
         int  * pa = & a;
         int  * pb = & b;
         swap(pa,pb);
         cout << *pa <<  ","  << * pb;
         return  0;
    }

     答案:

    填空(2分) 好怪异的返回值
     填空,使得程序输出指定结果
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #include <iostream>
    using  namespace  std;
    // 在此处补充你的代码
    getElement( int  * a,  int  i)
    {
         return  a[i];
    }
    int  main()
    {
         int  a[] = {1,2,3};
         getElement(a,1) = 10;
         cout << a[1] ;
         return  0;
    }

      输入 无  输出  10

    答案:

    10  填空(2分) 神秘的数组初始化
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    #include <iostream>
    using  namespace  std;
     
    int  main()
    {
         int  * a[] = {
    // 在此处补充你的代码
    };
         
         *a[2] = 123;
         a[3][5] = 456;
         if (! a[0] ) {
             cout << * a[2] <<  ","  << a[3][5];
         }
         return  0;
    }

      输入 无  输出  123,456

    答案:

      

      


      

Guess you like

Origin www.cnblogs.com/gongsuiqing/p/12442233.html