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 (~).