C++ Interview Questions - Page 1

 Q1. What is the full form of OOPS?

OOPS stands for Object Oriented Programming System.

Q2. What is a class?

A class is a data structure where entities, attributes and actions are clubbed under one name. Class is also considered as a carbon copy which reflects the entities, attributes and actions. In general, a class defines user defined data types. For example, when we say student class, it will have student name, class, age etc. as well as the methods needed for accessing or manipulating with its members.


class Student{
	char Name[20];
	char Class[15];
	int Age;
	void displayStdName();
	int getAge(char stdName);

Q3. What is an object?

An instance of a class is called as object. A class defines the skeleton of the data that we need to represent. Object represents the class with its own values to class members. For example, Student is a class and it will be represented as above. We can create various instance of class, which can have different values at different instance of time.

Student std1, std2;

Here std1 and std2 are two objects of the class Student.

Q4. What is inheritance?

Inheritance is the process of getting the properties of existing class. That means, there will be one existing class, and another additional class will be created which will have properties of existing class as well as its own additional features. Suppose we have three classes – Person, Teacher and Student. Here Person would be a existing class – a base class, Teacher and Student will have the same property as Person, in addition they will have some more features that differentiate them from person or makes them more stronger. It is similar to parent child relationship.

Q5. What is the role of protected access specifier?

Protected data members can be accessed by the class in which it is declared / defined and its derived classes. But these members are not available for any other classes which are not derived class.

Q6. What is encapsulation?

It is the process of combining the data and its functions into one single name is called encapsulation. It is the way we combine all related data and their methods into class. In other words, in a class we can see data members as well as its functions under single name. So it will be easy to get all related data together.

Q7. What is abstraction?

It is the process of hiding all the implementation details from others and providing only the required information to the user. More clearly, when we have to calculate average, there would be two functions – one to calculate the sum and other one to divide the sum by the total number. When user requests for average, he need not know what the sum of the numbers provided is. User will be provided only the function details which actually call average. But he will not be aware of how it has been calculated.

Q8. List the types of inheritance supported in C++.

There are different inheritances supported by C++. Some of them are: Single, Multilevel, Multiple, Hierarchical and Hybrid inheritance.

Q9. Explain the purpose of the keyword volatile.

When we use volatile on the variable, it tells the compiler that it can be changed externally. Therefore compiler will not optimize the code while referencing the variables.

Q10. What is an inline function?

When we prefix a keyword inline before any normal function, the function becomes inline function. These types of functions are considered as macros and they execute faster than the normal functions.

Q11. What is a storage class?

Storage classes are used to indicate the scope of the variables and functions in a program.

Q12. Mention the storage class’s names in C++.

There are 5 types of storage classes: auto, static, extern, register and mutable

Q13. What is the role of mutable storage class specifier?

Member variable of a constant class object can be altered by declaring it using mutable storage class specifier. This is applicable only for non-static and non-constant member variable of the class.

Q14. Distinguish between shallow copy and deep copy?

Shallow copy does memory allocation bit-by-bit from one object to another. Deep copy copies field by field from one object to another object. Deep copy is achieved by using copy constructor and or overloading ‘=’ (assignment operator).

Q15. What is pure virtual function in C++?

It is a virtual function with no function body and assigned with a value zero is known as pure virtual function.

Q16. What is an abstract class in C++?

Abstract class is the class with at least one pure virtual. One cannot instantiate abstract class. Objects are created out of its derived classes only.

Q17. What is a reference variable in C++?

This is another name for the variable. Both variable and reference variable will point to the same memory location. Hence changing the value of variable of reference variable will change the variable value.

Q18. What is role of static keyword on class member variable?

Static keyword is used for class member variables to share the common memory. That means, when objects are created using the class which has static member variable, then all the object’s static member variable will address same memory location. Hence this member variable will have same value in all the objects.

Q19. Explain the static member function.

A static member function can be called using the class name since static member exists before class objects comes into existence. It can access only static members of the class.

Q20. Which data type which can be used to store wide characters in C++?

Wide characters are stored using wchar_t data type.

Q21. What operators are used to access the class members?

Normal class members are accessed using Dot (.) operator and pointer members are accessed using Arrow (->) operator.

Q22. Can we initialize a class/structure member variable as soon as the it is defined?

Defining a class/structure is a type definition which tells which types of variables and functions should be present in the class / structure and will not get any memory for them.

Q23. What is the data type to store the Boolean value?

Boolean values are represented using bool keyword. This is the primitive data type introduced in C++.

Q24. What is function overloading?

Functions with same name and same list of parameters are called function overloading. It is also defined as function with same signature is called function overloading.

Q25. What is operator overloading?

Defining a new definition for the operator with respect to the class objects is known as operator overloading. For example, ‘+’ operator is used for adding two numbers. But if we use it to merge two numbers (5+8 = 58) then it is an operator overloading.

Q26. Do we have a String primitive data type in C++?

It is a class from Standard template library.

Q27. Name the default standard streams in C++.

There are four default standard streams in C++: cin, cout, cerr and clog.

Q28. Which access specifier/s can help to achieve data hiding in C++?

Private & Protected are the two access specifiers used to achieve data hiding.

Q29. When a class member is defined outside the class, which operator is used to associate the function definition to a particular class?

Scope resolution operator (::) can be used to serve this purpose.

Q30. What is a destructor? Can it be overloaded?

A destructor is the member function of the class with same name as the class name and it is prefixed with tilde (~) symbol. It gets executed automatically when the object is no more required in the program. It cannot be overloaded. Its only form is without the parameters.

Next >
Scroll to Top