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.


What is a consequence of forgetting to call delete on dynamically allocated memory?

  1. Stack overflow

  2. Memory leak

  3. Compilation error

  4. Automatic deallocation by the compiler

The correct answer is: Memory leak

A memory leak occurs when memory is allocated but not properly deallocated, resulting in a build-up of unused memory. Since the memory was allocated dynamically, the compiler will not automatically deallocate it, unlike in the case of static memory allocation. Therefore, options A, C, and D are incorrect as they do not address the issue of not calling delete. Option A, stack overflow, occurs when there is not enough space in the call stack for a function to execute, which is unrelated to the issue of not calling delete. Option C, compilation error, may occur if there is a mistake in the syntax of the code, but compilation will still be successful if the code is syntactically correct. Lastly, option D, automatic deallocation by the compiler, is incorrect because as mentioned before, the compiler only automatically deallocates statically allocated memory. Therefore, the correct answer is B, memory leak