I am writing a function that receives 3 square matrices in forms of 2D arrays. It should also receive the size. When I compile, I am getting such error! Note that I looked through the internet but could not find a solution
#include <stdio.h>
void matadd(int **a,int** b,int** c,int n){
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
c[i][j] = a[i][j] + b[i][j];
}
}
}
int main(){
int x[4][4]= {
{0,1,2,3},
{4,5,6,7},
{8,9,10,11},
{12,13,14,15}
};
int y[4][4]= {
{0,1,2,3},
{4,5,6,7},
{8,9,10,11},
{12,13,14,15}
};
int z[4][4] = {0};
matadd(&&x,&&y,&&z,4);
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
printf("%d ", z[i][j]);
}printf("\n");
}
return 0;
}
And the error is here:
matadd.c: In function ‘main’:
matadd.c:26:9: warning: passing argument 1 of ‘matadd’ from incompatible pointer type [-Wincompatible-pointer-types]
matadd(x,&&y,&&z,4);
^
matadd.c:2:6: note: expected ‘int **’ but argument is of type ‘int (*)[4]’
void matadd(int **a,int** b,int** c,int n){
^~~~~~
matadd.c:26:2: error: label ‘z’ used but not defined
matadd(x,&&y,&&z,4);
^~~~~~
matadd.c:26:2: error: label ‘y’ used but not defined
Note that Can't hardcode the size of array. Different times, different dimensions might be used!