⚙️ C++ Programming MCQs and Exam Questions

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

184 solved MCQs

Which of the following statement is correct?Answer: A reference is a constant pointer. Which of the following statement is correct?Answer: A variable can have multiple references. Which of the following statement is correct?Answer: An array of references is not acceptable. Which of the following statements is correct? 1. Pointer to a reference and reference to a pointer both are valid. 2. When we use reference, we are actually referring to a referent.Answer: Both 1 and 2 are correct. What happens when we try to compile the class definition in following code snippet? class Birds {}; class Peacock : protected Birds {};Answer: It will compile succesfully. Which of the following statements is incorrect?Answer: Friend keyword can be used on main(). Which of the following statement is correct regarding destructor of base class?Answer: Destructor of base class should always be virtual. Which of the following two entities (reading from Left to Right) can be connected by the dot operator?Answer: A class object and a member of that class. How can we make a class abstract?Answer: By making at least one member function as pure virtual function. Which of the following statements is correct when a class is inherited publicly?Answer: Public members of the base class become public members of derived class. Which of the following statements is correct about the constructors and destructors?Answer: Constructors can take arguments but destructors cannot. Which of the following access specifies is used in a class definition by default?Answer: Private Which of the following statement is correct with respect to the use of friend keyword inside a class?Answer: A class may be declared as a friend. Which of the following keywords is used to control access to a class member?Answer: Protected Which of the following can access private data members or member functions of a class?Answer: Any member function of that class. Which of the following type of data member can be shared by all instances of its class?Answer: Static Which of the following also known as an instance of a class?Answer: Object Constructor is executed when _____.Answer: an object is created Which of the following statements about virtual base classes is correct?Answer: It is used to avoid multiple copies of base class in derived class. How many objects can be created from an abstract class?Answer: Zero What does the class definitions in following code represent? class Bike { Engine objEng; }; class Engine { float CC; };Answer: has a relationship Which of the following statements is correct when a class is inherited privately?Answer: Public members of the base class become private members of derived class. Which of the following statements is correct?Answer: Both data and functions can be either private or public. What does a class hierarchy depict?Answer: It describes "kind of" relationships. Which of the following can be overloaded?Answer: Both B and C Which of the following means "The use of an object of one class in definition of another class"?Answer: Composition Which of the following is the only technical difference between structures and classes in C++?Answer: Member function and data are by default public in structures but private in classes. Which of the following statements are correct for a static member function? 1. It can access only other static members of its class. 2. It can be called using the class name, instead of objects.Answer: Both 1 and 2 are correct. A constructor that accepts __________ parameters is called the default constructor.Answer: no What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?Answer: Compile-time error.