C++ Question Bank
C++ Question Bank
C++ Question Bank
Question bank
List of Modules:
2. Which of the following is the correct syntax of including a user defined header files in C++?
a) #include <userdefined.h>
b) #include <userdefined>
c) #include “userdefined”
d) #include [userdefined]
14. Wrapping data and its related functionality into a single entity is known as _____________
a) Abstraction
b) Encapsulation
c) Polymorphism
d) Modularity
26. What is the scope of the variable declared in the user defined function?
a) whole program
b) only inside the {} block
c) the main function
d) header section
27. How many minimum number of functions should be present in a C++ program for its execution?
a) 0
b) 1
c) 2
d) 3
28. Which of the following is the default return value of functions in C++?
a) int
b) char
c) float
d) void
10 Mark questions
1. In detail bring out the differences between C and C++ [10 Marks]
2. Explain the OOP’s concepts in detail with neat representation [10 Marks]
3. State the benefits and the advantages of programming using OOP’s concepts. Conclude why is
C++ called as a OOP’s language [10 Marks]
4. Discuss about the various steps involved in the execution of C++ program [10 Marks]
5. Write and explain the format of a C++ program using classes [10 Marks]
Module 2: Classes and objects
1. Out of the following, which is not a member of the class?
a) Static function
b) Friend function
c) Constant function
d) Virtual function
8. Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both struct & union
10. The data members and functions of a class in C++ are by default ____________
a) protected
b) private
c) public
d) public & protected
11. When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) access is denied
13. Which operator a pointer object of a class uses to access its data members and member
functions?
a) .
b) ->
c) :
d) ::
16. How the objects are self-referenced in a member function of that class.
a) Using a special keyword object
b) Using this pointer
c) Using * with the name of that object
d) By passing self as a parameter in the member function
27. Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) both private & protected
10 mark Questions
1. Write note on the following and explain them in detail with examples [10 Marks]
i. Tokens
ii. Keywords
iii. Identifiers
iv. Constants,
2. With neat representation explain the different types of basic data types available in C++
[10 Marks]
3. Define the different types of User defined data types in C++ with examples [10 Marks]
4. Explain the concept of derived data types and symbolic constants with examples [10 Marks]
5. Illustrate the concept of Reference variables in C++ with example formats [10 Marks]
6. List the various operators in C++. Explain the concept of Scope resolution operator in detail with
an example program [10 Marks]
7. Define Manipulators. Explain the different types of manipulators in C++ with an example
Program [10 Marks]
8. Define functions in C++. Explain the different types of defining functions in C++ [10 Marks]
9. Explain function prototyping with an example program [10 Marks]
10. Introduce the feature in C++ which is used to define a function in one line. Explain the same with
an example program [10 Marks]
11. Illustrate the concept of function overloading with an example program [10 Marks]
12. Define the concept of FRIEND in functions. Explain the working of it with an example program
[10 Marks]
13. Write a note on [10 Marks]
i. Static data member
ii. Static member functions
Module 3: Constructors and destructors
1. Class function which is called automatically as soon as the object is created is called as __
A - Constructor
B - Destructor
C - Friend function
D - Inline function
6. Why constructors are efficient instead of a function init() defined by the user to initialize the
data members of an object?
a) Because user may forget to call init() using that object leading segmentation fault
b) Because user may call init() more than once which leads to overwriting values
c) Because user may forget to define init() function
d) All of the mentioned
10. How constructors are different from other member functions of the class?
a) Constructor has the same name as the class itself
b) Constructors do not return anything
c) Constructors are automatically called when an object is created
d) All of the mentioned
17. Which of the following represents the correct explicit call to a constructor of class A?
class A{
int a;
public:
A(int i)
{
a = i;
}
}
a) A a(5);
b) A a;
c) A a = A(5);
d) A a = A();
18. Which of the following constructors are provided by the C++ compiler if not defined in a class?
a) Default constructor
b) Assignment constructor
c) Copy constructor
d) All of the mentioned
#include <iostream>
using namespace std;
class A{
A(){
cout<<"Constructor called";
}
};
int main(int argc, char const *argv[])
{
A a;
return 0;
}
a) Constructor called
b) Nothing printed
c) Error
d) Segmentation fault
#include <iostream>
using namespace std;
class A{
public:
A(){
cout<<"Constructor called";
}
};
int main(int argc, char const *argv[])
{
A *a;
return 0;
}
a) Constructor called
b) Nothing printed
c) Error
d) Segmentation fault
#include <iostream>
using namespace std;
class A{
public:
int a;
};
int main(int argc, char const *argv[])
{
A a1 = {10};
A a2 = a1;
cout<<a1.a<<a2.a;
return 0;
}
a) 1010
b) 87368746
c) Error
d) Segmentation fault
#include <iostream>
using namespace std;
class A{
public:
int a;
A(int a){
this->a = a;
}
};
int main(int argc, char const *argv[])
{
A a1, a2(10);
cout<<a2.a;
return 0;
}
a) 10
b) Compile time error
c) Run-time error
d) No output
#include <iostream>
using namespace std;
class A{
public:
int a;
A(int a=0){
this->a = a;
}
};
int main(int argc, char const *argv[])
{
A a1, a2(10);
cout<<a2.a;
return 0;
}
a) 010
b) 100
c) 001
d) Error
#include <iostream>
using namespace std;
class A{
public:
int a;
A(){
cout<<"Constructor called";
}
};
int main(int argc, char const *argv[])
{
A *a1 = (A*)malloc(sizeof(A));
return 0;
}
a) Constructor called
b) Nothing printed
c) Error
d) Segmentation fault
#include <iostream>
using namespace std;
class A{
public:
int a;
A(){
cout<<"Constructor called";
}
} a;
int main(int argc, char const *argv[])
{
return 0;
}
a) Constructor called
b) Nothing printed
c) Error
d) Segmentation fault
#include <iostream>
using namespace std;
class A{
~A(){}
};
class B
{
public:
A a;
};
int main(int argc, char const *argv[])
{
B b;
return 0;
}
a)
A's Constructor called
B's constructor called
b)
B's Constructor called
A's constructor called
c) Error
d) Segmentation fault
35. Which of the following operator cannot be used to overload when that function is declared as
friend function?
a) -=
b) ||
c) ==
d) []
36. Which of the following operator can be used to overload when that function is declared as
friend function?
a) []
b) ()
c) ->
d) |=
37. In case of non-static member functions how many maximum object arguments a unary
operator overloaded function can take?
a) 1
b) 2
c) 3
d) 0
38. In the case of friend operator overloaded functions how many maximum object arguments a
binary operator overloaded function can take?
a) 1
b) 2
c) 3
d) 0
10 Mark questions
1. Can we have more than one constructor in a class? If, Yes explain the need for such a situation and
the method for invoking it with an example program [10 Marks]
2. Describe Destructor. Explain the importance of destructor through an example program
[10 Marks]
3. Explain the concept of Constructors in C++ with an example program [10 Marks]
4. Illustrate the concept of Copy Constructor in C++ with an example program [10 Marks]
5. Explain the concept of Multiple constructors in C++ with an example program [10 Marks]
6. Define Parameterized Constructors. Explain the working of this concept with a C++ example
program [10 Marks]
7. Elaborate in detail the special characteristics of a constructor in class. Explain Constructor and
Destructor with Proper syntax [10 Marks]
Module 4: Operator overloading and type conversion, Inheritance
1. Which feature of the OOPS gives the concept of reusability?
a) Abstraction
b) Encapsulation
c) Inheritance
d) None of the above.
2. Which of the following supports the concept that reusability is a desirable feature of a
language?
a) It reduces the testing time
b) It reduces maintenance cost
c) It decreases the compilation time
d) It reduced both testing and maintenance time
7. Which specifier makes all the data members and functions of base class inaccessible by the
derived class?
a) private
b) protected
c) public
d) both private and protected
8. If a class is derived privately from a base class then ______________________________
a) no members of the base class is inherited
b) all members are accessible by the derived class
c) all the members are inherited by the class but are hidden and cannot be accessible
d) no derivation of the class gives an error
class B: public A{
int a = 15;
public:
void func(){
cout<<"Hello this is class B\n";
}
};
#include <iostream>
#include <string>
using namespace std;
class A
{
float d;
public:
virtual void func(){
cout<<"Hello this is class A\n";
}
};
class B: public A
{
int a = 15;
public:
void func(){
cout<<"Hello this is class B\n";
}
};
16. What is the order of Constructors call when the object of derived class B is declared, provided
class B is derived from class A?
a) Constructor of A followed by B
b) Constructor of B followed by A
c) Constructor of A only
d) Constructor of B only
17. What is the order of Destructors call when the object of derived class B is declared, provided
class B is derived from class A?
a) Destructor of A followed by B
b) Destructor of B followed by A
c) Destructor of A only
d) Destructor of B only
18. Virtual functions in C++ tells the compiler to perform ______________________ on such
functions.
a) static binding
b) late binding
c) compile time binding
d) no binding
21. Which access specifier is used where one wants data members to be accessed by other classes
but not from outside objects?
a) private
b) protected
c) public
d) both protected and public
22. Which of the following describes the protected access specifier?
a) The variable is visible only outside inside the block
b) The variable is visible everywhere
c) The variable is visible to its block and to it’s derived class
d) The variable is not visible to its block
28. What are the things are inherited from the base class?
a) Constructor and its destructor
b) Operator=() members
c) Friends
d) All of the mentioned
10 Mark questions
1. Define Operator overloading representing the general format. Explain the need for overloading an
operator [10 Marks]
2. Illustrate the concept of Overloading Unary Operator with an example C++ program [10 Marks]
3. Elaborate the working of Binary operator overloading with an example C++ program [10 Marks]
4. Describe the different types of Type Conversions [10 Marks]
5. Using the concept of friend function explain the Binary operator overloading [10 Marks]
6. Discuss the importance of Inheritance in C++ programming. Write a note on the different types of
Inheritance with neat representations [10 Marks]
7. Explain Single Inheritance. Write a C++ program to explain the concept [10 Marks]
8. With the help of a C++ program explain the concept of deriving base class publicly from the
derived class [10 Marks]
9. With the help of a C++ program explain the concept of deriving base class privately from the
derived class [10 Marks]
10. Assume that you are given two base classes and one class derived from both the classes, explain
the type of Inheritance with a C++ example program [10 Marks]
11. Explain the concept of Multiple Inheritance with an example C++ program [10 Marks]
12. Illustrate the concept of deriving a single class from only one base class with neat representation
and a C++ program [10 Marks]
13. Elaborate the concepts of access specifiers used to derive a derived class from the base class with
examples [10 Marks]
14. Write an example C++ program to explain the concept of multilevel Inheritance [10 Marks]
15. Define Hierarchical Inheritance with neat representation and explain the same with a example
program [10 Marks]
16. Explain Hybrid Inheritance. Write a C++ program to explain the concept of the same [10 Marks]
17. Illustrate the concept of virtual base class with an example program [10 Marks]
Module 5: Pointers, Templates
1. What is the output of the following program?
#include<iostream>
using namespace std;
main() {
int a[] = {1, 2}, *p = a;
cout<<p[1];
}
a) - 1
b) - 2
c) - Compile error
d) - Runtime error
10. The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char
and returns a pointer to a pointer to a integer is ____________
a) int **fun(float**, char**)
b) int *fun(float*, char*)
c) int **fun(float*, char**)
d) int ***fun(*float, **char)
14. The pointer can point to any variable that is not declared with which of these?
a) const
b) volatile
c) both const & volatile
d) static
10 Mark questions
1. Explain the concept of Pointers in C++ with an example program [10 Marks]
2. Discuss in detail how pointers can be used to access the class members with an example program
[10 Marks]
3. Define the concept of templates in C++. With an example format explain how class templates are
written in C++ [10 Marks]
4. Define ‘this’ pointer. Explain in details the working of the pointer with an example program
[10 Marks]
5. Illustrate the concept of virtual functions with an example program [10 Marks]
6. Write note on [10 Marks]
a. Class templates with Multiple parameters
b. Function templates
7. Explain the concept of Function templates with Multiple parameters and Overloading of
Template functions with an example program in C++ [10 Marks]
8. Explain the concept of Overloading of template functions, member function templates with an
example program in C++ [10 Marks]