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

Disable ads (and more) with a membership for a one time $2.99 payment

Master C++ with our comprehensive quiz based on 'Thinking in C++'. Test your knowledge through flashcards and multiple-choice questions to enhance your understanding of C++. Prepare effectively for your exam!

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 mechanism does C++ have for handling unsuccessful memory allocation in new-expressions?

  1. try-catch exception handling

  2. Automatic garbage collection

  3. An error code returned by the new operator

  4. A compiler warning during compilation

The correct answer is: try-catch exception handling

In C++, try-catch exception handling is used to handle unsuccessful memory allocation in new-expressions. This is because C++ does not have automatic garbage collection, which is an automatic process of freeing up memory allocated by the program. Additionally, the new operator does not return an error code when unsuccessful, as it can only return a pointer to the allocated memory. A compiler warning during compilation may be helpful, but it does not handle the issue at runtime like try-catch exception handling does.