Any multidimensional array is in fact a one dimensional array elements of which are in turn arrays.
This declaration
int A[3][3][3]={0};
can be rewritten the following way
typedef int T[3][3];
T A[3];
So you have an array A
elements of which have type int[3][3]
If you want to declare a pointer to the first element of the array then you have to write
T *ptr = A;
where ptr
is a pointer to objects of type T
. As T
is an alias for int[3][3]
then the preceding declaration can be rewritten like
int ( *ptr )[3][3] = A;
In this case the loops will look like
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
printf("%d ", ptr[i][j][k] );
}
puts("");
}
}
If you want to declare a pointer to the whole array itself then you can write
int ( *ptr )[3][3][3] = &A;
and the loops will look like
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
printf("%d ", ( *ptr )[i][j][k] );
}
puts("");
}
}
But I am sure that in your assignment you need to use a pointer to the first element of the array as I showed initially.