What is a destructor?

A Destructor is used to delete any extra resources allocated by the object. A destructor function is called automatically once the object goes out of the scope.

Rules of destructor:

  • Destructors have the same name as class name and it is preceded by tilde.
  • It does not contain any argument and no return type.