0

I just can't get used to C++ syntax yet..
any intuitive explanation on

//delete [] foo
// and 
//delete foo[]

would be very appreciated.
to be more precise, let's say I have

int** foo = new int*[50]
for (int index = 0; index<50;++index)
     foo[index] = new int[50]

//foo = 2d 50x50 matrix
//now lets say i want to deallocate the memory of this matrix

for (index index=0;index<50;++index)
     delete[] foo[index]
delete[] foo

now I know I need to delete all the "inner" pointers that I've allocated before and then delete the pointer to a pointer.
but, my question is, what IS the [] after the delete used for? i mean if you leave it empty all the time why is even there? does it get any parameter some times? or we always just delete[] foo?

Itay.V
  • 169
  • 1
  • 7
  • 2
    if you use `new X[]` then you must use `delete[]` – Jonas Nov 25 '16 at 14:22
  • See: http://stackoverflow.com/a/2486055 – Jonas Nov 25 '16 at 14:23
  • There are two different *delete* operators. One for deleting single objects (`delete`) and one for deleting arrays of objects (`delete[]`). The `[]` simply differentiated between the different *delete* operators. – Galik Nov 25 '16 at 14:30

0 Answers0