Destructor in cpp is a another important concept in cpp.
when you create a object it occupies space in the memory to release the memory space so, that it will be available to other program.
What is Destructor
Destructor program in c++ : Destructor is used to release the memory which is occupied by the object.
It is the special member function whose name is same as that of the class name represented by tilde sign ( ~ ).
Destructor does not take any arguments and it does not return anything.
Therefore polymorphism is not possible on destructor.
Every class can have only one destructor.
C++ aromatically calls the destroy before object is destroyed.
//body of constructor
//body of destructor
2. we write a class with name class name data
3. declare one variable
4. next write constructor to create object
5. Next write destructor to destroy object
6. end with class
7. Write main function
8. create object of class
9. call constructor
10. End with program
Destructor program in c++
using namespace std;
data d1(20); //constructor call object created
cout<<"\nLets destroy object\n";
} // destructor calls
1. Execution starts with the main function.
2. Next call the parameterized constructor by passing value.
data d1(20); => which creates the object and constructor executed.
3. Control returned to main function
4. Next when we write} which is end of program then destructor is called explicitly.
5. And destructor code executed and object get destroyed.