0

Is there any way to pass 2D array to a function as function(arr,m,n) and the function defenition as void function(int **p,int m,int n) ie, Without explicitly specifying array size ??

Munavar Fairooz
  • 189
  • 1
  • 2
  • 10

1 Answers1

1

Let us C has a good explanation about how to pass two D array as parameter.

I usually use these two ways for passing 2D array as parameter. But you need to specify the size explicitly.

void display1(int q[][4],int row,int col){
    int i,j;
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
            printf("%d",q[i][j]);
        printf("\n");
    }
}

void display2(int (*q)[4],int row,int col){
    int i,j;
    int *p;
    for(i=0;i<row;i++)
    {
        p=q+i;
        for(j=0;j<col;j++)
            printf("%d",*(p+j));
        printf("\n");
    }
}
int main()
{
   int a[3][4]={1,2,3,4,5,6,7,8,9,0,1,6};
   display1(a,3,4);
   display2(a,3,4);
}
A.s. Bhullar
  • 2,310
  • 2
  • 20
  • 31