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.

- 21
- 2
-
Need to format the code and re post it. Also you can not dereference `void*`. Give example of any other data type. – iammilind Apr 16 '11 at 11:42
-
@iammilind: But you can dereference `void **` or `void ***`. – Oliver Charlesworth Apr 16 '11 at 11:49
-
Do you want to point at the *address* of the first element (i.e. point at the pointer), or point at the first element *itself*? – Oliver Charlesworth Apr 16 '11 at 11:50
-
This http://stackoverflow.com/questions/62512/three-dimensional-arrays-of-integers-in-c related question might provide you with some insights – celavek Apr 16 '11 at 11:56
1 Answers
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.

- 6,817
- 2
- 25
- 43