how to code a function that takes a 2d array as argument in c code example
Example 1: passing 2d array as parameter to function in c
#include <stdio.h>
void fun(int *arr, int m, int n)
{
int i, j;
for (i = 0; i < m; i++){
for (j = 0; j < n; j++)
printf("%d ", *((arr+i*n) + j));
printf("\n");
}
}
int main(void)
{
int arr[][4] = {{1, 2, 3,4}, {4, 5, 6,7}, {7, 8, 9,0}};
int m = 3, n = 4;
fun(&arr, m, n);
return 0;
}
Example 2: 2D Array In C
for(j = 0; j < n; j++)
{
for(i = 0; i < m; i++)
{
array[i][j] = 0;
}
}