Your function is declared with a parameter of type int *
. You are attempting to pass an argument of type int [50][50]
, which decays to pointer type int (*)[50]
. These pointer types are incompatible. Language does not support implicit conversion from int (*)[50]
to int
. Your code is not a valid C program, and I'm sure your compiler told you about it.
A more meaningful thing to do would be to declare your function as
void display (int n, int q[n][n])
and access your array elements in a natural way as
q[i][j]
However, for that you will have to use true array sizes as n
(i.e. 50 in your case). If you want to process a smaller sub-matrix of elements, you will have to pass its size separately.
But if you really want to use your "hack", you will have to use an explicit cast when calling your function
display ((int *) d, n);
and keep in mind that each row of your original array still contains 50 elements, as declared, regardless of the value of n
. This means that inside your function you will have to use 50 as row size multiplier
void display (int *q, int r) {
int i,j;
for (i=0;i<r;i++) {
for (j=0;j<r;j++) {
printf("%d\t", *(q + i*50 + j));
}
printf("\n");
}
}