Top 250+ C++ Constructor and Destructor Programming Interview Questions - 1

Question: 1

What is a constructor?

Constructor is a special function that initializes objects when they are created.

A constructor is automatically invoked when an object is created.

Question: 2

What are the functions of a constructor?

Functions of constructor:

The constructor function initializes the class object.

The memory space is allocated to an object.

Question: 3

What is a destructor?

A destructor is a function that removes the memory of an object which was allocated by the constructor at the time of creating a object.

It carries the same as the class tag, but with a tilde (~) as prefix.

Question: 4

Write the rules relating to a constructor.

The name of the constructor must be same as that of the class.

A constructor can have parameter list.

The constructor function can be overloaded.

The compiler generates a constructor, in the absence of a user defined constructor.

The constructor is executed automatically.

Related Questions