CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Aug 2002

    C++ Memory Management: What is the difference between 'delete' and 'delete[]'?

    Q: What is the difference between 'delete' and 'delete[]'?

    A: Whenever you allocate memory with 'new[]', you have to free the memory using 'delete[]'. When you allocate memory with 'new', then use 'delete' without the brackets. You use 'new[]' to allocate an array of values (always starting at the index 0).

    int *pi = new int; // allocates a single integer
    int *pi_array = new int[10]; // allocates an array of 10 integers
    delete pi;
    pi = 0;
    delete [] pi_array;
    pi_array = 0;

    Last edited by Andreas Masur; July 23rd, 2005 at 01:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.