C++: Pointers in 2D-arrays are confusing

前端 未结 1 520
抹茶落季
抹茶落季 2021-01-06 04:35

Can someone explain to me what is going on here? Consider the code

#include 

int main()
{
    int A[2][2] = {{0}};

    std::cout << A         


        
1条回答
  •  清酒与你
    2021-01-06 05:14

    int A[2][2] = {{0}}; This is a static 2D array, it's not a pointer to pointer, it's just a 1D array with special access.

    The fact that it's not a point to pointer, but a 2D array on a 1D array means that A[0] or *A accesses the array and returns the 1D array that is the first row. Then the second dereferentiation gets the actual value. This generalizes to nD if you have int A[x][y][z][t]....

    So the first two are the "same" address, but they are not the same type.

    0 讨论(0)
提交回复
热议问题