By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,402 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,402 IT Pros & Developers. It's quick & easy.

behavior of new

P: n/a
What is the standard behavior, if any, of the following.

int *p, n = 0;
p = new int[n];

Is p guaranteed not to be NULL, because it's not clear to me why it wouldn't be...

Regards,
Ryan
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Tino" <ti****@yahoo.com> wrote in message
news:f9*************************@posting.google.co m...
What is the standard behavior, if any, of the following.

int *p, n = 0;
p = new int[n];

Is p guaranteed not to be NULL, because it's not clear to me why it wouldn't be...
Regards,
Ryan


Its guaranteed not to be NULL, why should it be?

john

Jul 19 '05 #2

P: n/a
Wouldn't p==NULL if there wasn't enough memory for new to succeed? I
haven't been paying much attention to the standard recently, but I
assume this is still true. But, other than this error condition, p is
guaranteed to be a valid address (which NULL is not), and different
from any other pointers allocated with new or malloc (not just
different from other ints allocated).

Reggy

"Victor Bazarov" <v.********@attAbi.com> wrote in message news:<vi************@corp.supernews.com>...
"Tino" <ti****@yahoo.com> wrote...
What is the standard behavior, if any, of the following.

int *p, n = 0;
p = new int[n];

Is p guaranteed not to be NULL, because it's not clear to me why it

wouldn't be...

Yes, it is guaranteed not to be NULL, and it's guaranteed to be
different from any other "int"'s address in the system.

Victor

Jul 19 '05 #3

P: n/a
In article <f9*************************@posting.google.com> , tino52
@yahoo.com says...
What is the standard behavior, if any, of the following.

int *p, n = 0;
p = new int[n];

Is p guaranteed not to be NULL, because it's not clear to me why
it wouldn't be...


Assuming new didn't throw bad_alloc, p will be a unique, non-null
pointer, but dereferencing it will give undefined results.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.