1

I have this function

  • int findMax(int **a,int row,int column)

    and i am having 2-d array which is a[10][10].

  • Now what should i do so i can pass the address of this array to my function pointer that is **a ?

i saw other answers but the problem remain the same i have to pass the address but whenever i am trying to do this my compiler starts giving error and says cannot convert int to int and type mismatch error.

Give me your valuable suggestions and idea guys how should i do this?

Here is my code.

    #include<stdio.h>

  int findMax(int **a,int r,int c);

 int main()
 {
    int a[10][10],i,j,mx,r,c;


    printf("Enter the number of rows in the matrix\n");
     scanf("%d",&r);
     printf("Enter the number of columns in the matrix\n");
     scanf("%d",&c);
    printf("Enter the elements in the matrix\n");

    for(i=1;i<=r;i++)
    {
      for(j=1;j<=c;j++)
            scanf("%d",&a[i][j]);
    }
    printf("The matrix is\n");
    for(i=1;i<=r;i++)
     {
      for(j=1;j<=c;j++)
            printf("%d ",a[i][j]);
      printf("\n");
    }
    printf("\n");
    mx=findMax((int **)a,r,c);
    printf("The maximum elements in the matrix is %d\n",mx);
    return 0;
    }

    int findMax(int **a,int r,int c)
     {
    int t,i,j;
    t=a[0][0];
    for(i=1;i<=r;i++)
     {
      for(j=1;j<=c;j++)
      {
            if(a[i][j]>t)
                 t=a[i][j];
      }
      }
    return (t);
    
Community
  • 1
  • 1
Deepak Kumar
  • 107
  • 2
  • 2
  • 11

0 Answers0