【发布时间】:2012-02-08 10:29:45
【问题描述】:
我有以下疑问
我有一个结构数组。在我直接初始化它并在我的代码中使用之前。 但有人建议我使用指针而不是直接结构。但我无法正确获取指向 structre 数组的指针。
typedef struct
{
int a;
int b;
} cqiReport;
cqiReport s_cqiReport[2][2];
cqiReport *ptr[2], *ptr2, *ptr3;
s_cqiReport[0][0].a=1;
s_cqiReport[0][0].b=1;
*ptr= s_cqiReport;
*ptr2= s_cqiReport[0][0];
*ptr3= s_cqiReport[1][0];
我得到 ptr[0] 正确指向 s_cqiReport[0][0] 但 ptr[2] 指向一些垃圾。 如何让 ptr2[1] 指向 s_cqiReport[1][0]?
请帮忙 谢谢 DSP的家伙
【问题讨论】:
-
您使用 C 还是 C++ 工作?它看起来更像 C 而不是 C++,但你应该用语言名称重新标记你的问题。
标签: arrays pointers initialization structure