### delete 2d array

Hi everybody! I spent 3 hours at this code and haven't figured out how to delete 2d array from dynamical memory. I think something wrong with my function free(), but I'm not sure. Please help.
Here is a code:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950`` ``````#include #define COL 3 #define ROW 5 using namespace std; int** Array(int arr[][ROW]) { int **pd; pd=new int*[COL]; for(int i=0; i
Line 11: You've allocated an array of size 3.

Lines 12, 13: You're assigning values to an array of expected size 5. So pd[3] and pd[4] refer unallocated memory. This would at least fail at line 29.
The first index denotes rows while the second index denotes columns. So instead of

 ``123`` `````` pd=new int*[COL]; for(int i=0; i

it would be correctly to write

 ``123`` `````` pd=new int*[ROW]; for(int i=0; i

To delete an array allocated dynamically you shall use operator delete []pointer;
Last edited on
As I understood you I should change at line 28 `for(int i=0; i<ROW; i++)` to `for(int i=0; i<COL; i++)`. I have done, but it didn't help.
PLEASE: Be more precisely. What happens? What kind of error message will be reported? ...
well, it's indeed so (to match the loops):
 ``123`` `````` pd=new int*[COL]; for(int i=0; i

line 28:
` for(int i=0; i<COL; i++) `

2d arrays are hard to understand...
The first index denotes rows while the second index denotes columns. So instead of

 ``123`` `````` pd=new int*[COL]; for(int i=0; i

it would be correctly to write

 ``123`` `````` pd=new int*[ROW]; for(int i=0; i

Are you sure? Because after your interpretation I have mistakes in a string of integer.
May be that's your problem: You're assigning a 3x5 matrix to an 5x3.