2D array in Boolean function

i have a Boolean function containing 2D dynamic array, it'll retain either 0 or 1, how can i delete the dynamic array?
1
2
3
4
5
6
7
8
9
10
bool something (int** a,int b, int c)
{
    int **arr = new int*[b];
   for(int i=0;i<b;i++)
    arr[i]= new int[c];
if (...) return 0;
  else  ...
if (...) return 0;

}
Last edited on

1
2
3
4
5
6
7
8
Well the normal is

char *myArray;
myArray = new char[number of memory you require];

.. do something with the memory

delete [] myArray;
it is a 2d array so he will have to iterate over the array deleting each sub array.

Something like:
1
2
for(int row = 0; row < rows; ++row)
    delete [] row[array]; //array[row] if you want or *(array +row) 
giblit, good catch :)

I was just demonstrating how to delete allocated memory and the example was not directly connected with his code.

But yes andriac, based on your code giblit is the full solution.

Take care.
Topic archived. No new replies allowed.