What is a destructor used for in C++? 

  • To allocate memory. 
  • To initialize objects. 
  • To handle exceptions. 
  • To release resources.
A destructor is a special member function of a class that is executed whenever an object of that class goes out of scope or is explicitly destroyed. Its primary role is to release any resources that the object may have acquired during its lifetime.
Add your answer
Loading...

Leave a comment

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