Thread: delete array of pointers

  1. #1

    delete array of pointers

    i have declared and initialized an array of pointers like this:
    int* tmpArray=new int[size];

    whatz the difference between:
    delete[] tempArray;
    delete tempArray;

    when and where do i need the brackets? and whatz the diff?
    the compiler accepts both things.

    btw, i use borland builder 3.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Probably none if you're just deleting pointers to built in types rather than user defined classes, as most delete implementations will call the standard c function free(). However to be safe you should call delete [] whenever you allocate an array rather than a single object, and you must call delete [] for arrays of user defined types as it will call all of the destructors.

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    The best way to think about this is...

    if you used new then free with delete

    if you used new[] then free with delete[]

    if you used malloc() then free with free()

    remember this and you will be fine.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001


    Originally posted by Unregistered

    int* tmpArray=new int[size];
    Is this really an array of pointers? I thought it was something like this:
    int* Array[20];
    for(int i=0; i<20; i++)
      Array[i]=new int[size];

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Syntax for constant array of array pointers
    By BMintern in forum C Programming
    Replies: 4
    Last Post: 05-14-2008, 08:21 AM
  3. Array of Pointers to Arrays
    By Biozero in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 02:31 PM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM