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

Question: 1 / 565

What must be called before the storage is released in delete-expression?

Constructor

Destructor

The correct answer is called a destructor. When an object is allocated using the new operator in C++, it is the responsibility of the programmer to release the memory the object uses when it is no longer needed. This is done by calling the destructor, which frees the memory and other cleanup operations specific to the object. Constructors, on the other hand, are called when an object is being created, and are used to initialize its data members. The malloc function is used for dynamic memory allocation in C and is not relevant to C++. The new operator is used to allocate memory for an object, but it does not release the memory - that is the job of the destructor.

Get further explanation with Examzify DeepDiveBeta

new operator

malloc function

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy