By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,591 Members | 647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,591 IT Pros & Developers. It's quick & easy.

passing 2d array to function,error occurs

P: 1
#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)'
Mar 18 '18 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 2,398
Take a look at Arrays Revealed.
Mar 18 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.