Cannot cast array to pointer

前端 未结 8 984
陌清茗
陌清茗 2020-12-14 23:41

I have the following source:

#include 
using namespace std;

void main(int j)
{
    char arr[10][10];
    char** ptr;
    ptr = arr;
}
         


        
8条回答
  •  被撕碎了的回忆
    2020-12-15 00:09

    I thought arrays in c++ were just pointers.

    No, an array is a set of objects laid out contiguously in memory. In some circumstances, they are convertible to a pointer to the first element.

    So a char[][] could also be char**

    No. It is convertible to a pointer to the first one-dimensional array (which is the type char (*)[10] mentioned in the error message); but that array is not a pointer, so it is not convertible to a pointer-to-pointer.

提交回复
热议问题