In C++, what is the main purpose of destructors ?
2025
In C++, what is the main purpose of destructors ?
- A.
They initialize an object
- B.
They are used for memory deallocation
- C.
They destroy the class
- D.
They return a value
Attempted by 100 students.
Show answer & explanation
Correct answer: B
C++ destructors are special member functions automatically invoked when an object's lifetime ends. Their primary purpose is to release resources like memory, file handles, or network connections that the object acquired during its lifetime.