Top 80+ Solved CPP Programming MCQ Questions Answer
Q. Which of the followings is/are automatically added to every class, if we do not write ourown?
a. Copy Constructor
b. Assignment Operator
c. A constructor without any parameter
d. All of the above
Q. When a copy constructor may be called?
a. When an object of the class is returned by value.
b. When an object of the class is passed (to a function) by value as an argument.
c. When an object is constructed based on another object of the same class
d. All of the above
Q. Implicit return type of a class constructor is:
a. not of class type itself
b. class type itself
c. a destructor of class type
d. a destructor not of class type
Q. Which of the following is true about constructors?1) They cannot be virtual.2) They cannot be private.3) They are automatically called by new operator.
a. All 1, 2, and 3
b. Only 1 and 3
c. Only 1 and 2
d. Only 2 and 3
Q. Output of following program?#include<iostream>using namespace std;class Point { Point() { cout << "Constructor called"; }}; int main(){ Point t1; return 0;}
a. Compiler Error
b. Runtime Error
c. Constructor called
d. None of the above
Q. #include<iostream>using namespace std;class Point {public: Point() { cout << "Constructor called"; }};int main(){ Point t1, *t2; return 0;}
a. Compiler Error
b. Constructor called Constructor called
c. Constructor called
d. None of the above
Q. Which of the following is FALSE about references in C++?
a. References cannot be NULL
b. A reference must be initialized when declared
c. Once a reference is created, it cannot be later made to reference another object; it cannot be reset.
d. References cannot refer to constant value
Q. Which of the following functions must use reference?
a. Assignment operator function
b. Copy Constructor
c. Destructor
d. Parameterized constructor
Q. Output of following C++ program?#include<iostream>using namespace std;int main(){ int x = 10; int& ref = x; ref = 20; cout << "x = " << x << endl ; x = 30; cout << "ref = " << ref << endl; return 0;}
a. x = 20; ref = 30
b. x = 20; ref = 20
c. x = 10; ref = 30
d. x = 30; ref = 30
Q. What is the difference between struct and class in C++?
a. All members of a structure are public and structures don’t have constructors and destructors
b. Members of a class are private by default and members of struct are public by default. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.
c. All members of a structure are public and structures don’t have virtual functions
d. All of the above
Q. Predict the output of following C++ program.#include<iostream>using namespace std;class Empty {};int main() {cout << sizeof(Empty);return 0;}
a. A non-zero value
b. 0
c. Compiler Error
d. Runtime Error
Q. class Test { int x;};int main() { Test t; cout << t.x;return 0;}
a. 0
b. Garbage Value
c. Compiler Error
d. None
Q. Which of the following is true?
a. All objects of a class share all data members of class
b. Objects of a class do not share non-static members. Every object has its own copy.
c. Objects of a class do not share codes of non-static methods, they have their own copy
d. None of the above