C++ Memory Management: What is the difference between 'delete' and 'delete[]'?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

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

Hybrid View

  1. #1
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    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).

    Code:
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center