tags:

views:

166

answers:

3

new char[1] and new char,essentially the same thing,hm?

+15  A: 

You have to delete char[1] with delete[] according to the standard, so not quite identical.

Daniel Earwicker
Yeap, if one ignores this "not quite identical" he plants undefined behavior.
sharptooth
IIRC, you even have to `delete[]` `new char[0]`.
sbi
@sbi: Yes, you do have to `delete[]` what `new char[0]` returns.
sharptooth
A: 

No. char[1] is of type char*, while char is of type char.

Chris
However, `new char` is of type `char *`, so that's not the difference.
Daniel Earwicker
+2  A: 

The objects created are the same, the (invisible) bookkeeping used is not.

That means that you can use the chars in the same way, but you must delete them with the matching delete operator (delete versus delete[])

MSalters