new char[1]
and new char
,essentially the same thing,hm?
views:
166answers:
3
+15
A:
You have to delete char[1]
with delete[]
according to the standard, so not quite identical.
Daniel Earwicker
2010-08-24 08:42:54
Yeap, if one ignores this "not quite identical" he plants undefined behavior.
sharptooth
2010-08-24 08:47:35
IIRC, you even have to `delete[]` `new char[0]`.
sbi
2010-08-24 08:54:03
@sbi: Yes, you do have to `delete[]` what `new char[0]` returns.
sharptooth
2010-08-24 14:36:44
However, `new char` is of type `char *`, so that's not the difference.
Daniel Earwicker
2010-08-24 08:44:25
+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
2010-08-25 10:00:05