Here is what int[2][2] looks like in memory:
int[2] int[2]
That is, the array immediately follows another array.
Here is what int[2] looks like in memory:
int int
That is, int immediately follows another int.
So, here it looks int[2][2] in memory:
int int int int ^ ^ | |___ this is arr[1][1] | |____ this is p[1], assuming sizeof(int*) == sizeof(int)
If you press arr on int** , I'm going to name the result p . Then he points to the same memory. When you do p[1][1] , you do not get arr[1][1] . Instead, the program executes, it reads the value in p[1] , sets this value to int size and plays it. If this second int contains, say, the value "21", then you simply tried to dereference the pointer "25" (if int is 4 bytes). It is not right.
Arrays do not match with pointers, and 2-D arrays are, of course, not the same as pointers to pointers.
Steve jessop
source share