Destructors in C++

Destructors in C++

Destructors in C++

 

DESTRUCTOR

A Destructor is also a special member function like a constructor .  A destructor destroys the class object created by the constructor .

A destructor neither requires any argument nor return any value .

Destructor has the same name as their class name preceded by  tilde  (~) symbol .

Destructor is only one way to destroy the object created by the constructor .

It is not possible to define more than one destructor .

 

SYNTAX :

~ < class_name > ( ) {

//  body of destructor

}

 

CODE :

// C++ program to demonstrate the execution of constructor
// and destructor
#include <iostream>
using namespace std;
class Test {
public:
    // User-Defined Constructor
    Test() { cout << "\n Constructor executed"; }
    // User-Defined Destructor
    ~Test() { cout << "\nDestructor executed"; }
};
main()
{
    Test t;
    return 0;
}

OUTPUT :

Constructor executed
Destructor executed



 

Topics Covered :

  • destructors
  • c++ destructors
  • learn c++
  • c++ tutorial
  • object-oriented programming
  • programming
  • c++

 


 

 


 

Thanks for reading this blog. Hope you get satisfied with the blog and definitely this blog must have valued your time and effort of reading.

Take a time to connect our other digital creations such as Instagram , Facebook and Youtube.

 

🧑‍💻🧑‍💻 Social Media Links of Tech DCode :

👉🏻 YouTube : https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
👉🏻 Instagram : https://www.instagram.com/thetechdcode/
👉🏻 Facebook Page : https://www.facebook.com/thetechdcode
👉🏻 Twitter : https://twitter.com/thetechdcode
👉🏻 Telegram Channel : https://t.me/thetechdcode
👉🏻 Tech DCode Linktree : https://linktr.ee/thetechdcode
👉🏻 My Personal Handles : https://linktr.ee/virtualshivamin

🧑‍💻🧑‍💻 Social Media Links of SHIVAM SINGH (OWNER) :

👉🏻 Instagram : https://www.instagram.com/virtualshivamin/
👉🏻 Facebook Page : https://www.facebook.com/virtualshivamin/
👉🏻 Twitter : https://twitter.com/virtualshivamin/
👉🏻 Personal Linktree : https://linktr.ee/virtualshivamin 

 


Leave a Reply

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