|
-
February 11th, 2003, 07:02 AM
#1
Question about delete a char* pointer
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
-
February 11th, 2003, 07:20 AM
#2
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...
-
February 11th, 2003, 07:23 AM
#3
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|