So if I declare a 2D array like
int a[5][5] and I go into memory view I can see that
a is not a vector of vectors (or pointer to pointer in other words), it is instead just one big vector (and the compiler knows that when you give it a[m][n] it just displays the (5*m + n)th element from the vector). This I already knew but I just wanted to confirm it.
But then we have this code:
1 2 3 4 5
|
int main()
{
int a[5][5] = { 0 };
cout << a + 5 << ", " << *(a + 5) << '\n';
}
|
And I find it very peculiar that it just prints the same things twice (it prints the starting address of a incremented by 5). But if
*(a+5) prints out an address that means that
a is indeed a pointer to pointer? Or it means that the C language represents a 2D array internally as a big vector but treats it as a vector of vectors?.. the second option sound more plausible but.. that means that the dereference operator, '*', is unreliable. Since *(a+5) does not return what is found at address
a+5, but instead returns the address itself.
Can somebody explain to me what is going on here exactly? Any help is appreciated. Thanks in advance :)