A pointer to 2d array

后端 未结 6 1756
予麋鹿
予麋鹿 2020-11-28 22:26

I have a question about a pointer to 2d array. If an array is something like

int a[2][3];

then, is this a pointer to array a?<

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 22:52

    you can point to 2d array like 1d array

    #include 
    int main()
    {
       int array[2][2] = {{0,1}, {2,3}}; // array
       int *ptr;
       ptr=(int*)array;
       std::cout << *(ptr)   << '\n';//out 0
       std::cout << *(ptr+1) << '\n';//out 1 
       std::cout << *(ptr+2) << '\n';//out 2
       std::cout << *(ptr+3) << '\n';//out 3
    }
    

提交回复
热议问题