It all depends on how you declared the array supposed to be passed to your function.
If you declared it like this
int my_array[10][10]; // array declaration
then
void fun (int m[10][10]); // prototype of a function accepting my_array
fun (my_array); // calling the function
is what you are looking for.
In that case, m
is a constant pointer to 100 contiguous int
s that are accessed as a 10x10 2D array.
Other possible variant:
int * my_array[10];
for (i = 0 ; i != 10 ; i++) my_array[i] = malloc (10*sizeof(int));
void fun (int m[10][]); // these syntaxes are equivalent
void fun (int * m[10]);
or this one:
int ** my_array;
my_array = malloc (10 * sizeof (int*));
for (i = 0 ; i != 10 ; i++) my_array[i] = malloc (10*sizeof(int));
void fun (int m[][]); // these syntaxes are equivalent
void fun (int * m[]);
void fun (int ** m);
or this pathological one:
int (* my_array)[10];
int a0[10];
int a1[10];
/* ... */
int a9[10];
my_array = malloc (10 * sizeof (int *));
my_array[0] = a0;
my_array[1] = a1;
/* ... */
my_array[9] = a9;
void fun (int m[][10]); // these syntaxes are equivalent
void fun (int (* m)[10]);
If your variable declaration and function prototype are not consistent, you will not access the array properly from within your function, read incoherent values, and mess up your memory and possibly crash if you attempt to modify an element.
If you have nothing better to do, you can read this little essay of mine on the subject for further details.