Practice mode C++

What does a plain new expression do when it cannot allocate the requested memory?

Correct answer C. It throws std::bad_alloc

Explanation

By default, operator new reports failure by throwing std::bad_alloc, unlike C's malloc, which returns NULL. Checking the result of a plain new against nullptr is therefore pointless. If you really need a null result instead of an exception, use the non-throwing form new (std::nothrow) T, declared in .

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.