Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


When is a destructor called in C++?

  1. Immediately after the constructor

  2. Just before a program ends

  3. When an object goes out of scope or is deleted

  4. After a class function is executed

The correct answer is: When an object goes out of scope or is deleted

A destructor is a special function in C++ that is responsible for destroying an object's allocated resources before its memory is deallocated. It is called when an object goes out of scope or is explicitly deleted using the 'delete' keyword. Option A is incorrect because a destructor is not called immediately after the constructor, as constructors and destructors serve different purposes. Option B is also incorrect because a destructor can be called multiple times during a program's execution, not just before it ends. Option D is incorrect because a destructor is not called after a class function is executed, unless that function explicitly deletes the object.