Can someone explain to me what is going on here? Consider the code
#include <iostream> int main() { int A[2][2] = {{0}}; std::cout << A << std::endl; // First stdout line std::cout << *A << std::endl; // Second stdout line std::cout << *(*A) << std::endl; // Third stdout line } It seems to me that A should be an array of 2 pointers to arrays, each of which should contain 2 pointers to ints. However, when running the code, the following is written to stdout:
0x7a665507cf80 0x7a665507cf80 0 To me, this makes it seem like the memory address of the first element in A (printed on the first stdout line) is the same as the memory address of the first element in *A. How is this possible, considering that A and *A are clearly two different arrays (since dereferencing A and *A gives different results)?
An alternative interpretation of the output is that the memory address 0x7a665507cf80 either contains the value 0x7a665507cf80 (i.e. a pointer located on that position—in this case A—points to itself) or 0, depending on if it is accessed from A or *A, which also doesn't really make sense to me.
typeid(A)withtypeid(*A)- they will be different, sinceAand*Ahave different types, even if they have the same valueA"should be an array of 2 pointers to array, each of which should contain 2 pointers toints"?