指针数组的最大尺寸为2D数组?

时间:2014-01-31 19:11:13

标签: c arrays pointers

我正在使用以下内容来允许我动态选择我使用的2D数组。

const prog_uint16_t (*p)[8];
p = arrayname;

这适用于尺寸为[3] [8]的2D数组,但是我需要[10] [1025]。
当我尝试这个时:

const prog_uint16_t (*p)[1025];
p = arrayname;

我收到“无法转换”错误。

有什么想法吗?谢谢!

编辑:

这是有效的2D数组的声明。没有声明的是相同的方式,只是使用不同数量的条目([10] [1025])。

const prog_uint16_t TRI[3][8]={{10,20,30,40,50,60,70,80},{11,21,31,41,51,61,71,81},{12,22,32,42,52,62,72,82}};

谢谢!

2 个答案:

答案 0 :(得分:1)

您无法更改常量指针的大小和类型,当然您可以更改指向的数据或

else但是不能调整这种类型的p指针

看这段代码可能对你有所帮助

const int x;             // x cannot be modified

const int* pX = &x;      // pX is the address of a const int
                 // and can't be used to change an int

 *pX = 4;                 // illegal - can't use pX to change an int

 int* pInt;       // address of normal int

  pInt = pX;       // illegal - cannot convert from const int* to int*

成功

答案 1 :(得分:0)

指向二维数组的指针采用以下形式:

prog_uint16_t (*p)[x][y];

所以,例如:

const prog_uint16_t array[1][2] = {{1,2}};
const prog_uint16_t (*p)[1][2] = &array;