| View previous topic :: View next topic |
| Author |
Message |
Krishna Guest
|
Posted: Wed Sep 29, 2004 4:09 am Post subject: Use of new in C++ |
|
|
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
|
Posted: Wed Sep 29, 2004 4:17 am Post subject: Re: Use of new in C++ |
|
|
"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
|
Posted: Wed Sep 29, 2004 8:27 am Post subject: Re: Use of new in C++ |
|
|
| 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 |
|
 |
|