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.


Why does C++ prefer new and delete over malloc() and free()?

  1. For performance reasons

  2. To guarantee object initialization and cleanup

  3. Because of compiler restrictions

  4. To support exception handling

The correct answer is: To guarantee object initialization and cleanup

C++ prefers new and delete over malloc() and free() because of compiler restrictions and support for exception handling. While C++ is able to compile using malloc() and free(), it may cause issues and make it more difficult to guarantee object initialization and cleanup, which is important for memory management. Additionally, new and delete are able to support exception handling, making it a more robust option. This is why B is the correct answer.