How I will pass a 2D array in a function. I take input from keyboard but when I pass it into function it doesn't work.
for example
#include<bits/stdc++.h>
using namespace std;
void printGrid(int M, int N, int arr[][N])
{
for(int i=0; i<M; i++)
{
for(int j=0; j<N; j++)
{
printf("%d ",arr[i][j]);
}
printf("\n");
}
}
int main()
{
int M,N;
scanf("%d %d",&M,&N);
int arr[M][N];
printGrid(M,N,arr);
return 0;
}
This solution doesn't work. It says N
was undeclared on this scope.
Is there any way to work with 2D array in Function ?