Define Destructors?

0 votes
Shikhar Arora asked 06-Dec-2019 in Technology by Shikhar Arora

Define Destructors

1 Answer

0 votes
Sangsaptak Pal answered 27-Jan-2020 by Sangsaptak Pal

Destructor is the antonym to Constructor both in name ans meaning.

Constructor is a special method that initializes the data members of the class and thus allocates the memory space to them.

On the other hand, destructor is a member function which destructs or deletes an object.

A destructor is automatically called when:

  • the function ends
  • the program ends
  • a delete operator is used
  • a block containing the local variables end

They are usually named with the same name as the class name preceded by a tilde (~).