Cannot cast array to pointer

前端 未结 8 989
陌清茗
陌清茗 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:12

    Arrays aren't pointers.

    An array decays to a pointer in most circumstances, but this isn't recursive. So a T[] decays to a T *, but a T[][] doesn't decay to a T**.

    I suggest reading the whole of the C FAQ chapter on arrays and pointers; in particular, the section on 2D arrays and pointers-to-pointers.

提交回复
热议问题