In C++, what is the main purpose of destructors ?

2025

In C++, what is the main purpose of destructors ?

Answer: B. They are used for memory deallocationC++ destructors are special member functions automatically invoked when an object's lifetime ends. Their primary purpose is to release resources like memory,…

  1. A.

    They initialize an object

  2. B.

    They are used for memory deallocation

  3. C.

    They destroy the class

  4. D.

    They return a value

Attempted by 284 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.

Explore the full course: Tpsc Assistant Technical Officer

Loading lesson…