What happens when new cannot allocate the requested memory in its normal form?
Options
- A. It normally returns NULL
- B. It normally throws std::bad_alloc
- C. It always terminates the operating system
- D. More than one of the above
- E. None of the above
Quiz Practice:
B. It normally throws std::bad_alloc
Answer: It normally throws std::bad_alloc
In its normal form, the C++ new operator throws a std::bad_alloc exception if the requested memory cannot be allocated.
This allows the program to handle allocation failure using exception handling.
For example, a program can use try and catch to handle the allocation failure.