In C, two dimensional arrays are stored in the way just like linear arrays, but they are indexed using a double pointer. That is, if we define
int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}}.
a first points to something like
{p1 = 0x7fff5fbffb58 , p2 = 0x7fff5fbffb70, p3 = 0x7fff5fbffb88}
then p1 points to 1, p2 points to 4 and p3 points to 7.
So why don’t compilers allow for a conversion from the two dimensional array to the double pointer which is theoretically possible? Although 2-D arrays are stored one by one, but the index information can always be passed to an arbitrary double pointer.
It’s not theoretically possible. 2d arrays are not indexed using a double pointer – the compiler convert it to one index. For example, if you have
int a[3][5], and you accessa[i][j], the compiler convert it to((int[])a)[5*i+j]. (Your explanation is completely wrong)Because of all of that, if you want to convert
int[][]toint**, you need to allocate memory to save the addresses of all the sub-arrays, and get the address of it. Just(int**)awill not work.