[C/C++ Basic Exercises] Review Questions Volume 2

 1. The initialization of data members in a class can be realized through ( ) in the constructor, or through ( ) in the constructor. (initialization table, function body)

2. Assuming that AB is a class, when the statement "AB a[10];" is executed, the number of times the system will automatically call the constructor of this class is (10).

3. Assuming that the user does not define a constructor for a class named AB, the system implicitly defines a constructor for it (the default constructor).

4. Let p be a pointer variable pointing to a dynamic object, then when the delete p statement is executed, the (destructor) of this class will be called automatically

5. If the member function "void fun();" of class A is defined as a friend function of class B, a statement should be added to the definition of class B: (friend void A::fun(); )

6. This pointer is an implicit pointer, which is implicit in each class (non-static member function)

7. The constructor can have parameters, but cannot have a return value.

8. All objects of a class have their own data members, and they share member functions.

9. The initialization of the static member function of the class should be done outside the class. (this sentence is wrong)

Static member variables of a class must be initialized outside the class, and functions do not need to be initialized. It is wrong to say that functions are initialized.


1. The function of the scope operator is ( ).

A identifies the level of the scope B indicates the extent of the scope

C the size of a given scope D identifies which class a member belongs to

 2. The following ( ) cannot be used as a member of a class.

A A pointer to its own class object B A reference to its own class object

C an object of its own class D an object of another class

3. Among the characteristics of the following static members, ( ) is wrong.

A When describing a static member, add the modifier static

B Static data members are initialized outside the class

When C refers to a static data member, add <class name> and scope operator before the name of the static data member

D Static data members are not shared by all objects

4. It is known that f1(int) is a public member function of class A, p is a pointer to member function f1(), and it is correct to use ( ).

A p=f1 B p=A::f1 C p=A::f1() D p=f1()

5. The function of operator ->* is ( ).

A is used to represent the operation of pointing to an object pointer to a pointer to a class member

B is used to represent the operation of the object on the pointer to the class member

C is used to represent the operation of pointing to object pointers to class members

D is used to represent operations on members of object classes

6. Let p be a pointer to a data member m of class A, and A1 be an object of A. If you assign a value of 5 to m, ( ) is correct.

A A1.p=5 B A1->p=5 C A1.*p=5 D *A1.p=5

7. It is known that the print( ) function is a constant member function of a class, and it has no return value. Among the following expressions, ( ) is correct.

A void print ( ) const B const void print ( )

8. For the description of int * pa[5];, ( ) is correct.

A pa is a pointer to an array, and the pointed array has 5 elements of int type.

B pa is a pointer pointing to the fifth element in an array, which is an int variable.

C pa[5] represents the value of the fifth element of an array.

D pa is a pointer array with 5 elements, each element is an int pointer.

9. The purpose of setting virtual base class is ( ).

A Simplify the program B Eliminate ambiguity C Improve operating efficiency D Reduce object code

10. The member initialization list of the multi-layer derived class constructor with virtual base class must list the constructor of the virtual base class, so that the sub-objects of the virtual function will be initialized ( ).

A related to the number of derived classes under the virtual base class B multiple times C twice D once

11. In the following use of abstract classes, ( ) is wrong.

A can define an object of an abstract class B can define a pointer of an abstract class

C can define a reference to an abstract class D can define a derived class of an abstract class

 12. In the member initialization list of the constructor of the derived class, ( ) cannot be included.

A base class constructor

Initialization of subobjects in B derived classes

Initialization of subobjects of C base classes

Initialization of general data members in D-derived classes

13. In the following description about the new operator, () is wrong.

A It can be used to dynamically create objects and object arrays;

B objects or arrays of objects created with it can be deleted using the delete operator;

When C uses it to create an object, it calls the constructor;

When D uses it to create an array of objects, an initial value must be specified.

Under normal circumstances, the parameter of the copy constructor is ( ).

A. The reference name of an object

B. An object name

C. A member name of an object

D. An object pointer name


Guess you like

Origin blog.csdn.net/Catherine_77/article/details/128914247