void f(int **m, int w, int h )
{
int i,j;
for(i=0;i < w ; i++)
{
for(j=0;j<h;j++)
{
printf("%5d", m[i][j]); // *( *(m + i) + j ) ??
}
printf("\n");
}
return;
}
int main()
{
int a[3][3]={{1,2,3},{4,5, 6},{7,8,9}};
f(a,3,3);
}
this code is trying to print a 2d matrix
but i get a segmentation fault.
Your matrix is not of type
int **, its type isint[3][].int **means a pointer to an array of pointers. You don’t have an array of pointers, you have an array of 3-integer-arrays. It’s not the same thing.If you want you can change your code to take that into account.
To access m[i][j] use: