Discussion
In C++, what is the main purpose of destructors ?
Answer: B
The main purpose of a C++ destructor is that they are used for memory deallocation.
A destructor, named with a tilde (~ClassName), runs automatically when an object goes out of scope or is deleted. Its job is to release resources the object holds, typically freeing dynamically allocated memory and closing files.
Initialising an object is the constructor's job. Destructors destroy objects, not the class, and they cannot return a value.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development