CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Unhappy 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

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    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...

  3. #3
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Talking

    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
  •  





Click Here to Expand Forum to Full Width

Featured