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.
Loading...
Related Quiz
- A friend function is defined outside the class but has the ability to access the _______ members of the class.
- The result of the expression (true || _______) in C++ will always be true.
- How does C++ treat an enum regarding its type and size?
- A member function that is used to initialize the class members is known as a _______.
- In C++, if a class makes a non-member function its friend, that function gets the ability to access the _______ and _______ members of the class.