passing 2d array to function,error occurs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pardeep Bhatt
    New Member
    • Mar 2018
    • 1

    passing 2d array to function,error occurs

    #include <math.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <assert.h>
    #include <limits.h>
    #include <stdbool.h>
    void func(int** a, int rows, int cols)
    {
    int i,j,t=0;
    for(i=0;i<rows; i++)
    for(j=0;j<cols; j++)
    if(i==j)
    {
    if(a[i][j]==1)
    continue;
    else
    {
    t=1;
    break;
    }
    }
    else
    {
    if(a[i][j]==0)
    continue;
    else
    {
    t=1;
    break;
    }
    }
    if(t==0)
    printf("It is an Identity matrix");
    else
    printf("Not Identity");

    }
    int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */int n,i,j,t=0;
    scanf("%d",&n);
    int a[n][n];
    for(i=0;i<n;i++ )
    for(j=0;j<n;j++ )
    scanf("%d",&a[i][j]);
    func(&a,n,n);
    return 0;
    }
    [Error] cannot convert 'int (*)[n][n]' to 'int**' for argument '1' to 'void func(int**, int, int)'
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Take a look at Arrays Revealed.

    Comment

    Working...