⚙️ C++ Programming MCQs and Exam Questions

Practice 184 approved ⚙️ C++ Programming MCQs and exam questions from the 💻 Programming subject.

184 solved MCQs

Can a class have virtual destructor?Answer: Yes Destructor has the same name as the constructor and it is preceded by ______ .Answer: ~ For automatic objects, constructors and destructors are called each time the objectsAnswer: enter and leave scope Which constructor function is designed to copy objects of the same class type?Answer: Copy constructor Which of the following statement is correct?Answer: Both A and B. Which of the following statement is incorrect?Answer: Both B and C. When are the Global objects destroyed?Answer: When the program terminates. Copy constructor must receive its arguments by __________ .Answer: only pass-by-reference A function with the same name as the class, but preceded with a tilde character (~) is called __________ of that class.Answer: destructor A union that has no constructor can be initialized with another union of __________ type.Answer: same Which of the following gets called when an object goes out of scope?Answer: destructor Which of the following statement is correct?Answer: Destructor destroys the complete object. __________ used to make a copy of one class object from another class object of the same class type.Answer: copy constructor Constructors __________ to allow different approaches of object construction.Answer: can be overloaded Which of the following statement is correct?Answer: A destructor has the same name as the class in which it is present. Which of the following cannot be declared as virtual?Answer: Both A and C If the copy constructor receives its arguments by value, the copy constructor wouldAnswer: call itself recursively Which of the following are NOT provided by the compiler by default?Answer: Copy Destructor It is a __________ error to pass arguments to a destructor.Answer: syntax If the programmer does not explicitly provide a destructor, then which of the following creates an empty destructor?Answer: Compiler A __________ is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.Answer: default constructor How many default constructors per class are possible?Answer: Only one Which of the following statement is correct about destructors?Answer: A destructor has no return type. Which of the following statement is correct?Answer: A constructor has the same name as the class in which it is present. Which of the following implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class?Answer: Compiler A destructor takes __________ arguments.Answer: no Destructor calls are made in which order of the corresponding constructor calls?Answer: Reverse order Which of the following never requires any arguments?Answer: Default constructor A class's __________ is called when an object is destroyed.Answer: destructor Destructors __________ for automatic objects if the program terminates with a call to function exit or function abort.Answer: are not called