Back To C++ Constructors & Destructors
a destructor is a special member function in class that has the same name as that of class and is followed by a tilde(~)
a destructor is called when memory allocated to object is deallocated
//program to demonstrate destructor in class student #include
#include
#include
class student { int rollno; char name[20]; int marks; public: student() { cout<<"\nconstructor called here"; rollno=1; strcpy(name,"abcdef"); } ~student() { cout<<"\ndestructor called here"; } void showdata() { cout<<"\nrollno is "<