# Run-time error with dynamically allocated 3-D array

• 10-21-2005
OceanDesigner
Run-time error with dynamically allocated 3-D array
Following some literature I was able write the code below to dynamically allocate a two dimensional array. I made the attempt to extrapolate the code to a the three dimensional array. The code below for the 3-D array compiles, but gives me a fatal run-time error. Since the 3-D array is not used anywhere in the code (I am just setting it up for now), the run-time error must come from the algorithm I am using to allocate. Evidently, I don't fully understand what is going on. I appreciate any help I can get.

Thanks, Jeff

Code:

```/*******TWO DIMENSIONAL ARRAY*******/ int nx,ny; struct GRID {         float        x1;         float        y1;         float        x2;         float        y2; }; GRID **grid2, *grid1; nx = 8; ny = 4; grid1 = new GRID[nx*ny]; grid2 = new GRID * [nx]; for (i=0; i<nx; i++)         grid2[i] = &(grid1[i*ny]);  // Sets up a 2-D array with dimension grid[8][4] /*******THREE DIMENSIONAL ARRAY*******/ int ndt,nx,ny; struct CELL {         float        height;         int        col; }; CELL ***cell3,**cell2, *cell1; ndt = 100; nx = 8; ny = 4; cell1 = new CELL[ndt*nx*ny]; cell2 = new CELL * [ndt*nx]; cell3 = new CELL ** [ndt]; for (t=0; t<ndt; t++)         cell2[t] = &(cell1[(t*nx)]); for (t=0; t<ndt; t++)         for (i=0; i<nx; i++)                 cell3[t][i] = &(cell2[(t*nx)][(i*ny)]);  // Sets up a 3-D array with dimension cell[100][8][4]```
• 10-21-2005
quzah
Your code is C++ not C. C doesn't have the new operator.

Quzah.
• 10-21-2005
OceanDesigner
Going to post in C++
I guess you are right. Well then at the risk of cross-posting, I will take this up with the C++ forum.