On This Page

This set of CPP Programming Multiple Choice Questions & Answers (MCQs) focuses on Cpp Programming Set 1

Q1 | Which of the followings is/are automatically added to every class, if we do not write ourown?
  • Copy Constructor
  • Assignment Operator
  • A constructor without any parameter
  • All of the above
Q2 | When a copy constructor may be called?
  • When an object of the class is returned by value.
  • When an object of the class is passed (to a function) by value as an argument.
  • When an object is constructed based on another object of the same class
  • All of the above
Q3 | Constructors have _____ return type.
  • void
  • char
  • int
  • no
Q4 | Implicit return type of a class constructor is:
  • not of class type itself
  • class type itself
  • a destructor of class type
  • a destructor not of class type
Q5 | 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.
  • All 1, 2, and 3
  • Only 1 and 3
  • Only 1 and 2
  • Only 2 and 3
Q6 | Output of following program?#includeusing namespace std;class Point {Point() { cout << "Constructor called"; }}; int main(){Point t1;return 0;}
  • Compiler Error
  • Runtime Error
  • Constructor called
  • None of the above
Q7 | #includeusing namespace std;class Point {public:Point() { cout << "Constructor called"; }};int main(){Point t1, *t2;return 0;}
  • Compiler Error
  • Constructor called Constructor called
  • Constructor called
  • None of the above
Q8 | Which operator is having the highest precedence?
  • postfix
  • unary
  • shift
  • equality
Q9 | Which of the following is FALSE about references in C++?
  • References cannot be NULL
  • A reference must be initialized when declared
  • Once a reference is created, it cannot be later made to reference another object; it cannot be reset.
  • References cannot refer to constant value
Q10 | Which of the following functions must use reference?
  • Assignment operator function
  • Copy Constructor
  • Destructor
  • Parameterized constructor
Q11 | Output of following C++ program?#includeusing namespace std;int main(){int x = 10;int& ref = x;ref = 20;cout << "x = " << x << endl ;x = 30;cout << "ref = " << ref << endl;return 0;}
  • x = 20; ref = 30
  • x = 20; ref = 20
  • x = 10; ref = 30
  • x = 30; ref = 30
Q12 | What is the difference between struct and class in C++?
  • All members of a structure are public and structures don’t have constructors and destructors
  • 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.
  • All members of a structure are public and structures don’t have virtual functions
  • All of the above
Q13 | Predict the output of following C++ program.#includeusing namespace std;class Empty {};int main() {cout << sizeof(Empty);return 0;}
  • A non-zero value
  • 0
  • Compiler Error
  • Runtime Error
Q14 | class Test {int x;};int main() {Test t;cout << t.x;return 0;}
  • 0
  • Garbage Value
  • Compiler Error
  • None
Q15 | Which of the following is true?
  • All objects of a class share all data members of class
  • Objects of a class do not share non-static members. Every object has its own copy.
  • Objects of a class do not share codes of non-static methods, they have their own copy
  • None of the above
Q16 | A member function can always access the data in __________, (in C++).
  • the class of which it is member
  • the object of which it is a member
  • the public part of its class
  • the private part of its class
Q17 | Which of the following is not correct for virtual function in C++?
  • Must be declared in public section of class.
  • Virtual function can be static.
  • Virtual function should be accessed using pointers.
  • Virtual function is defined in base class.
Q18 | Which of the following is not correct (in C++)?1. Class templates and function templates are instantiated in the same way2. Class templates differ from function templates in the way they are initiated3. Class template is initiated by defining an object using the template argument4. Class templates are generally used for storage classes
  • -1
  • (2), (4)
  • (2), (3), (4)
  • -4
Q19 | Which of the following cannot be passed to a function in C++?
  • Constant
  • Structure
  • Array
  • Header file
Q20 | Which of the following, in C++, is inherited in a derived class from base class?
  • Constructor
  • Destructor
  • Data members
  • Virtual methods
Q21 | Which of the following is a correct statement?
  • Composition is a strong type of association between two classes with full ownership.
  • Composition is a strong type of association between two classes with partial ownership.
  • Composition is a weak type of association between two classes with partial ownership.
  • Composition is a weak type of association between two classes with strong ownership.
Q22 | Which of the following is not a correct statement?
  • Every class containing abstract method must be declared abstract.
  • Abstract class can directly be initiated with ‘new’ operator.
  • Abstract class can be initiated.
  • Abstract class does not contain any definition of implementation.
Q23 | When a method in a subclass has the same name and type signatures as a method in thesuperclass, then the method in the subclass _____ the method in the superclass.
  • Overloads
  • Friendships
  • Inherits
  • Overrides
Q24 | It is possible to define a class within a class termed as nested class. There are _____ types of nested classes.
  • 2
  • 3
  • 4
  • 5
Q25 | When one object reference variable is assigned to another object reference variable then
  • a copy of the object is created.
  • a copy of the reference is created.
  • a copy of the reference is not created.
  • it is illegal to assign one object reference variable to another object reference variable.