Answer:
Destructor is a function or method which is used to deallocated the memory which is allocated by the constructor in the program.The destructor is used to delete the object or destruct the object.
Step-by-step explanation:
The Purpose of Destructor is to delete the object from the memory which is created by Constructor.
The Destructor have same name as the class name in c++.
In c++ we use destructor like that
#include <iostream>
using namespace std;
class Hello
{
public:
Hello () //constructor defined
{
cout << "Hey constructor is called here:" << endl;
}
~Hello() //destructor defined
{
cout << "Now destructor is called here:" << endl;
}
};
int main()
{
Hello h; //constructor is called
cout << "function main is closing...." << endl;
return 0;
}