If I dynamically allocate a 2D array(malloc it),
int r,c;
scanf("%d%d",&r,&c);
int **arr = (int **)malloc(r * sizeof(int *));
for (i=0; i<r; i++)
arr[i] = (int *)malloc(c * sizeof(int));
and then later on pass it to a function whose prototype is:
fun(int **arr,int r,int c)
There is no issue. But when I declare a 2D array like VLA i.e.
int r,c;
scanf("%d%d",&r,&c);
int arr2[r][c];
It gives me an error when I try to pass it to the same function. Why is it so?
Is there any way by which we can pass the 2nd 2D array(arr2) to a function?
I Know there are lots of similar questions but I didn't find one which address the same issue.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…