Re: regarding new operator
* kris:
I am a beginner to c++ programming. I just want to know what is the
use of new operator.
If there is no sufficient memory to be allocated then what does the
call to this new return.
The common new expression doesn't return in the ordinary way if there is
not sufficient memory for the request.
It either hangs, crashes or throws a std::bad_alloc exception.
The standard mandates the std::bad_alloc exception, but the exact
behavior depends on the operating system and on the standard library
implementation. You don't need to worry about hangs or crashes, because
you can't do anything about them anyway. Dealing with std::bad_alloc as
an exception can be very difficult because the system is most likely low
on memory, therefore the recommended way (when it matters) is to avoid
dealing with it by installing a so-called "new handler" that reports
failure and terminates the program instead of throwing an exception.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?