Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any difference between these two in c++?

Tags:

c++

syntax

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

like image 565
wamp Avatar asked Aug 24 '10 08:08

wamp


Video Answer


2 Answers

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

like image 131
Daniel Earwicker Avatar answered Sep 27 '22 23:09

Daniel Earwicker


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[])

like image 41
MSalters Avatar answered Sep 27 '22 22:09

MSalters