If you have an array like this
int test0[][2] = { /*...*/ };
then a pointer to elements of the array looks the following way
int ( *p )[2] = test0;
Or
int test1[][3] = { /*...*/ };
int ( *p )[3] = test1;
and you can access elements of the array using the pointer the same way as you do with the array that is for example p[i][j].
Pay attention to that this code snippet
t[0] = (int) test0;
t[1] = (int) test1;
is unsafe and does not make sense. The size of a pointer can be greater than the size of the type int. And moreover the objects t[0] and t[1] are not pointers. They are integers.
You could define an array of pointers of the type void * and then explicitly cast each element of the array to the required type.
For example
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
enum { N0 = 2, N1 = 3 };
int test0[N0][N0] =
{
{ 0, 2 },
{ 1, 3 }
};
int test1[N1][N1] =
{
{ 10, 20, 30 },
{ 40, 50, 60 },
{ 70, 80, 90 }
};
void **t = malloc( 2 * sizeof( void * ) );
t[0] = test0;
t[1] = test1;
for ( size_t i = 0; i < N0; i++ )
{
for ( size_t j = 0; j < N0; j++ )
{
printf( "%d ", ( ( int ( * )[N0] )t[0] )[i][j] );
}
putchar( '\n' );
}
putchar( '\n' );
for ( size_t i = 0; i < N1; i++ )
{
for ( size_t j = 0; j < N1; j++ )
{
printf( "%d ", ( ( int ( * )[N1] )t[1] )[i][j] );
}
putchar( '\n' );
}
putchar( '\n' );
free( t );
return 0;
}
tas declared is a pointer to an integer, not to a 2d array. No wonder the compiler is complaining. Also, maybe you should have listened to it when it lamented that you were trying to assigntest0andtest1tot[0]andt[1]since I'm sure that's the reason you cast them.int ***t = malloc(2*sizeof(int**))but it won't work neither - I had thent[0] = test0And I'm not sur if int*** is a real type ?t[0]is anint**, how would it know the internal array dimensions?