【发布时间】:2012-09-12 00:18:01
【问题描述】:
我搜索了 stackoverflow 并看到了我的问题中的每个单词组合,但没有看到我的问题。
我有一个整数数组,它恰好是一个二维数组。
const int themap[something][something] = { {0, ...
我有一个结构,我想在我的程序中有一个指向这个数组的指针
typedef struct {
int** mymap;
} THE_STRUCT
在我的程序中,我想通过结构的指针迭代数组的值,但是如果我尝试通过 .语法
int value;
THE_STRUCT mystruct;
mystruct = (int**) themap;
...
//access the map data from mystruct's pointer?
value = mystruct.mymap[x][y];
//doesn't seem to return correct values
如果我直接使用数组(作为全局变量),那么从图片中取出结构,同样的函数也可以工作
int value;
...
//access the map directly
value = themap[x][y]
//everyone is happy!
我想使用该结构,因为实际上它会携带其他信息,并且我需要能够将指针分配给具有不同数据的其他数组。
【问题讨论】:
-
我很惊讶这甚至可以编译。
-
themap可以被解释为一个指针,并且任何指针-指针转换在C语言中都是合法的。
标签: c pointers multidimensional-array struct