Here is the list of most asked C++ interview questions for beginners as well as an experienced programmer.

These interview questions are also well suited for those who want to give viva exams in their school. We tried our best to explain every C++ concept in short and simple way.

1. What is the use of the static keyword in C++?

when static keyword used with variables inside a function then its value is preserved between successive calls to that function for the lifetime (program) but cannot be accessible outside the scope or function in which it has been declared.

when static used with class functions or variables, that function can be accessed without an instance of the class (i.e objects) and can access only static members. Also, all the objects share the same copy of a function.

2. Struct vs Class in C++
By default all the members in structure are public, whereas in class all the members are private

3. Why main() function is important?
Because the execution of the program starts from the main() function. If there will be no main function then there will be an error.

4. When a copy constructor is called?
Whenever an object is passed by value then the copy constructor is called to create copy of the object.

5. Can << (Insertion) ans >> (Extraction) operator be overloaded?

6. What is a virtual destructor?
When the destructor of a class is declared proceeding with a virtual keyword then it becomes virtual destructor. It helps in getting derived class destructor to get invoked when its object gets out of scope.

7. What is a virtual constructor?
There is no virtual constructor in C++.

8. What is namespace in C++?
Namespace in C++ allows to group together the entities like class, function, variables etc under a name. It is a declarative region that provides scope to different identifiers inside it. Example: std

9. What is :: in C++?
:: is scope resolution operator. Scope resolution operation resolve to which namespace or scope do the following member belongs to.

10. Stream classes which allows file operations in C++?

  • fstream
  • ifstream
  • ofstream

11. How many times destructor of a class will be called for 10 objects?
10 times. Because for each object, destructor is called 1 time that is only when it gets destroyed.

12. What is include used for?
include is a preprocessor command. It is used with the library file name or class name. It directs preprocessor to insert them into the program code before the compilation of the program begins.

13. What is scope in C++?
Scope refers to a region which defines the visibility or lifetime of variables/objects. The scope is created by using set of braces ({}).

14. What is friend function in C++?
A friend function is a function which has access to all private members of a class in which it has been declared as a friend using friend keyword.

15. What is encapsulation?
Encapsulation means wrapping up of data and functions into a single unit. Encapsulation is implemented by creating objects.

16. What will be the value of ‘i’ and ‘j’ after the execution of given code? Why?

Value of i will equal 7 and j will equal 6 because with post increment operator variable is first used then gets modified.

17. What is ‘std’ in C++?
std is a default namespace provided in C++.

18. Difference between ‘new’ and ‘malloc()’ in C++.
mallov vs new in C++

19. What is the use of ‘delete’ operator in C++?
delete free up the dynamic memory which was allocated by new operator.

20. What is destructor in C++?
Destructor in C++

21. What is dynamic binding?
The decision to call which function for a function call when done in runtime then it is termed as dynamic binding. Basically, dynamic binding is the implementation of function overriding using virtual keyword. It is also known as late binding.

22. What is Pure Virtual function?
Pure Virtual Function in C++

23. What is Abstract class in C++?
Abstract class in C++

24. What will be the output of the following code?

interview question on C++
Because q and r is ponting to same memory address but different from p.

25. Difference between Abstraction and Encapsulation in C++?
Abstraction means hiding implementation details and showing only important information. E.g making a class variable private so that it can only be accessed through function.

Encapsulation means wrapping up of data and functions into a single unit. E.g creating class.

Encapsulation implements Abstaction.

Leave a Reply

Close Menu