A Destructor is a special member function whose name is the same as that of its class name except that it is preceded by a tilde (~) symbol.

A destructor is used to perform the cleanup process (typically deallocating the dynamically allocated memory).

Like a constructor, destructor too has no return type. Only one destructor is possible for a class. So destructors cannot be overloaded.

The Compiler calls destructor implicitly just before an object goes out of its scope.

How to Call Destructor In C++ Example program

using namespace std;
class Hello1{ 
public: Hello1(){ 
cout<<"Constructor is called here"<<endl;
} ~ Hello1(){ 
cout<<"Destructor is called here"<<endl;
} }; 
int main(){ 
Hello1 h1;
return 0; 

Output:-Constructor is called here
Destructor is called here

Explanation of the program

Constructor gets called as soon as the memory is allocated to the object of the class sample. Destructor gets called just before the object h1 dies.

This article is written by our awesome writer
Comments to: How to Call Destructor In C

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories


Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page


Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
    Strength indicator
    Log In | Lost Password