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 one difference between dynamic memory allocation in C and C++?

  1. C requires manual deallocation, unlike C++

  2. C++ requires type casting from void*, unlike C

  3. C allows direct constructor calls, unlike C++

  4. C++ ensures destructors are called, unlike C

The correct answer is: C++ ensures destructors are called, unlike C

C++ ensures destructors are called when using dynamic memory allocation, while in C the programmer must manually handle this. One key difference is that C++ is an object-oriented language, so it handles memory allocation and deallocation automatically through the use of constructors and destructors. In contrast, C is a procedural language, meaning it does not have built-in support for objects and requires manual memory management. As a result, C++ ensures destructors are called to prevent memory leaks, while in C it is the programmer's responsibility to deallocate memory. Options A, B, and C are incorrect because they either describe features that are shared between C and C++, such as manual deallocation and direct constructor calls, or describe differences unrelated to dynamic memory allocation.