Click to See Complete Forum and Search --> : Question about delete a char* pointer


George2
February 11th, 2003, 06:02 AM
Hi, everyone!

Look at the following codes,

--------
const char* p = "12345";
char* q = "54321";
--------

If I want to release the memory, should I use

--------
delete[] p;
delete[] q;
--------

or should I use

--------
delete p;
delete q;
--------


Thanks in advance,
George

Andreas Masur
February 11th, 2003, 06:20 AM
Neither one...since you did not explicitely allocated memory for them by using the 'new' operator...

There is a simple rule:

If you 'new'ed memory then you have to 'delete' it. If you 'new[]'ed memory then you have to 'delete[]' it.

In all other cases you do not 'delete' something... :cool:

George2
February 11th, 2003, 06:23 AM
Thanks, Andreas buddies!

George

Originally posted by Andreas Masur
Neither one...since you did not explicitely allocated memory for them by using the 'new' operator...

There is a simple rule:

If you 'new'ed memory then you have to 'delete' it. If you 'new[]'ed memory then you have to 'delete[]' it.

In all other cases you do not 'delete' something... :cool: