# Thread: difference between **v and v[][]

1. ## 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 2. ## Re: Difference between **v and v[][]

int v 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 3. The problem is that when it is passed to a function as an argument, Smatrix, like any other array, is converted to a pointer to its first element. Therefore, what is passed is an int (*)[N], i.e., a pointer to an array of N ints. This is certainly different from an int**, i.e., a pointer to a pointer to an int. 4. int v; is stored in memory as 100 consecutive integers, which the compiler allows you to access two dimensionally by internally performing a simple stride calculation: index = y*10+x.

int **v; is a pointer to 10 other pointers which each point to 10 ints (after the appropriate allocation). To get to any one of those ints requires following two pointers to where they point to.

As you can see, they both require completely different work "under the hood". There is no way any compiler can treat these the same way because they're fundamentally very different. 5. I think this illustrates the difference. 6. Not bad, though even those images don't do everything required to show how different they really are.
For example, the arrow from the declaration to the first box in the second image indicates the following of a pointer, but the arrow in the first image is not, because in that case the array is the data and no pointers are involved at all. So that arrow should be removed. 7. This better? 8. Great! I wasn't expecting you to spend any more effort to produce such a nice diagram, but hopefully the OP really gets it now  9. Perhaps it can go into the FAQ somehow. 10. There is the SourceForge Wiki. Feel free to create an article on the matter. 11. Popular pages Recent additions 