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 .
Answer checked How we write and check questions
Discussion