I this post we have provided part 2 of the most common C++ interview questions along with answers. We recommend you to try to answer the questions, before referring to the given answer. If you find any mistake or a better alternate solution we are happy to see your suggestions and comments

1. What is the difference between structures in C and C++?

Ans : C structures cannot contains functions and does support access specifiers

2. What is the difference between C++ structures and classes?

Ans : In structure member are public by default and in class members are private by default

3. What is empty class, size of a empty class and reason for the size of empty class?

Ans : Any class that does not contain any members is called empty class. The size of empty class is compiler dependent commonly it will be one byte. This minimum size of empty class is to ensure not two objects to the empty class will point to the same memory location.

4. What are the default members of a class?

  • Constructor – Classname()
  • Destructor – ~Classname()
  • Copy constructor – Classname(const Classname &)
  • Assignment operator – Classname & operator = (const Classname &)

5. What is virtual function?

Ans : Any function declared with a virtual key word is a virtual function.

6. What is pure virtual function?

Ans : Any virtual function assigned 0 during declaration is a pure virtual function.

7. Can a pure virtual function have definition?

Ans : Yes

8. What is Abstract class?

Ans : Any class that contains minimum one pure virtual function is a Abstract class

9. What is a Interface class or Pure abstract class?

Ans : Any class that contains only pure virtual functions is a Interface class

10. What is virtual table or virtual function table?

Ans : Virtual function table is a array of virtual function pointers