wamp
wamp

Reputation: 5949

Any difference between these two in c++?

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

Upvotes: 5

Views: 219

Answers (3)

MSalters
MSalters

Reputation: 179779

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

Upvotes: 2

Chris
Chris

Reputation: 1333

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

Upvotes: -1

Daniel Earwicker
Daniel Earwicker

Reputation: 116654

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

Upvotes: 15

Related Questions