0

can a single dimension array made to point to the first address of a three dimensional array, e.g. int *array; int ***array3D; array=*array3D; I need the first array to point to the first address of the second array. I need only the first address into the pointer. Can anyone please suggest any alternatives to point to the starting address? Thanks in advance.

harsha
  • 21
  • 2

1 Answers1

0

This kind of thing happens all the time when you're processing 2D and 3D images.

That you wrote (array = *array3D) obviously won't compile though because the types don't match. array3D is an **int and array is an *int.

If you have array3D set up correctly, as such (for example):

int ***array3D = new int **[zsize];
for(int z = 0 ; z < zsize ; ++z)     
{
    array3D[z] = new int *[ysize];
    for(int y = 0 ; y < ysize ; ++y)
    {  
         array3D[z][y] = new int [xsize];
    }
}

Then you can access things like array3D[z][y] (points to the x=0 element for the given z and y) or &(array3D[z][y][x]) (points to element x, y, z) or *(array3D[z]) (points to the y=0 and x=0 element for the given z), and will then all be of type int *. I suggest writing out how your data is organized.

Of course you have to manually delete this structure as well and if you're doing this in a product, you should be careful that you handle exceptions well and don't leak, but this another topic.

Chris A.
  • 6,817
  • 2
  • 25
  • 43