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 are destructors for static objects called?

  1. After main() exits or when exit() is called

  2. Before main() enters

  3. After the last instance of the object is destroyed

  4. Never, they must be explicitly invoked

The correct answer is: After main() exits or when exit() is called

Static objects are objects created within a class that can be accessed without creating an instance of the class. Static objects are destructed after main() exits or when exit() is called, because they have a longer lifetime than automatic objects, which are destructed when they go out of scope. B is incorrect because destructors for static objects are not called before main() enters. C is incorrect because the last instance of the object may not be the last to be destroyed. D is incorrect because destructors for static objects are automatically invoked when their lifespan ends.