I need a little advice. Are all those 3 ways of passing static, multidimensional array (here I have 3-dimensional, I guess for 4 dimensions it would be analogical) to a function are correct?
Here's the code:
#include <stdio.h>
void fun1(int ***tab, int n, int m, int p)
{
int i,j,k;
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
for(k=0; k<p; k++)
{
printf("tab[%d][%d][%d] = %d\n", i, j, k, tab[i][j][k]);
}
printf("\n");
}
printf("\n");
}
}
void fun2(int tab[2][3][2])
{
int i,j,k;
for(i=0; i<2; i++)
{
for(j=0; j<3; j++)
{
for(k=0; k<2; k++)
{
printf("tab[%d][%d][%d] = %d\n", i, j, k, tab[i][j][k]);
}
printf("\n");
}
printf("\n");
}
}
void fun3(int tab[][3][2])
{
int i,j,k;
for(i=0; i<2; i++)
{
for(j=0; j<3; j++)
{
for(k=0; k<2; k++)
{
printf("tab[%d][%d][%d] = %d\n", i, j, k, tab[i][j][k]);
}
printf("\n");
}
printf("\n");
}
}
int main()
{
int tab[2][3][2] =
{
{{0, 1}, {2, 3}, {3, 4}},
{{5, 6}, {7, 8}, {9, 10}}
};
fun1(tab,2,3,2);
printf("--------------------------\n");
fun2(tab);
printf("--------------------------\n");
fun3(tab);
return 0;
}
There seem to be a problem with fun1 but can't really understand what does it mean: expected ‘int ***’ but argument is of type ‘int (*)[3][2]’|. Does it mean that only fun2 and fun3 are valid in this case?