It is a special function of a class which automatically invoked whenever execution controls goes out of scope.
Rules for constructing destructor
1. Destructor name and class name must be exactly same#include<conio.h> #include<iostream.h> class A { public: A(){ cout<<"\n Constructor is called "; } ~A(){ cout<<"\n Destructor is called"; } }; void main() { int x; clrscr(); A obj1; if(x){ A obj2; } getch(); }O/P
Constructor called Constructor called Destructor called