difference between **v and v[][]
hi.
i have a function like this
Code:
void print_matrix(int **t)
when i call it with my dynamic matrix everything is ok.
Code:
int **Dmatrix;
Dmatrix = malloc(N * sizeof(int*)); //N righe
for (i = 0; i < N; i++) {
Dmatrix[i] = malloc(N * sizeof(int));
}
print_matrix(Dmatrix);
but if i call it with a static matrix i obtain a warning (and a segmentation foult :( )
Code:
int Smatrix[N][N];
print_matrix(Smatrix);
warning is:
warning: passing argument 1 of ‘print_matrix’ from incompatible pointer type
Re: Difference between **v and v[][]
int v[10][10] indicates 10 rows and 10 columns. But **v indicates multiple rows and columns. we can change that rows and columns any time.
If we pass this to function it allocates based on the index. So it needs that much memory to store that array or pointer in a function.
So if you pass with Smatrix[N][N] it needs N*N memory but in the pointer it is different. that is why it gives warning