Difficulty: Easy
Correct Answer: The default destructor of the object is called.
Explanation:
Introduction / Context:
C++ relies on deterministic destruction (RAII) to release resources such as memory, files, sockets, and locks. Understanding which function runs at scope exit is essential for writing safe code that cleans up reliably, even when exceptions occur.
Given Data / Assumptions:
Concept / Approach:
When an object’s lifetime ends (e.g., the block closes), C++ automatically calls its destructor. There is no such thing as a parameterized destructor; the language grammar forbids parameters. The constructor runs at object creation, not at destruction. Therefore, the correct choice is that the object’s (default) destructor is called at scope exit, ensuring cleanup of the object and its subobjects in reverse order of construction.
Step-by-Step Solution:
Verification / Alternative check:
Instrument the destructor to log a message. You will see it triggered at scope exit or on delete for dynamically allocated objects; constructors never run at scope exit.
Why Other Options Are Wrong:
Default constructor at scope exit: constructors initialize, not finalize.
Parameterized destructor: invalid concept in C++.
None of the above: wrong because the destructor is indeed called.
Common Pitfalls:
Final Answer:
The default destructor of the object is called.
Discussion & Comments