C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Use of new in C++

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Krishna
Guest





PostPosted: Wed Sep 29, 2004 4:09 am    Post subject: Use of new in C++ Reply with quote



What is the differnce in these new operators

char *a = new char[21];
char *a = new char(21);

Do the type of brac matter ?.. If yes what do they signify ?..
Back to top
Victor Bazarov
Guest





PostPosted: Wed Sep 29, 2004 4:17 am    Post subject: Re: Use of new in C++ Reply with quote



"Krishna" <annamrak (AT) anz (DOT) com> wrote...
Quote:
What is the differnce in these new operators

char *a = new char[21];
char *a = new char(21);

Do the type of brac matter ?.. If yes what do they signify ?..

Yes, the first form allocates and array of 21 characters and returns
a pointer to the first character. The second form allocates a single
character and initialises it to 21.

What book are you reading that doesn't explain this?

V



Back to top
Marcin Kalicinski
Guest





PostPosted: Wed Sep 29, 2004 8:27 am    Post subject: Re: Use of new in C++ Reply with quote



Quote:
What is the differnce in these new operators

char *a = new char[21];
char *a = new char(21);

Do the type of brac matter ?.. If yes what do they signify ?..

They do matter. The first line allocates an array of 21 chars (and does not
initialize it) while the second line allocates one char with initial value
of 21.

cheers,
Marcin



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.