简体   繁体   English

如何在 C 中定义指向指针数组的指针数组?

[英]How to define an array of pointers to array of pointers in C?

Lets say I have the following pointer arrays:假设我有以下指针 arrays:

const char* m1[5] = { "bla", "asdada", "sadasde", "wrskm", "adjsad" };
const char* m2[5] = { "xxx", "yyy", "zzz", "uuu", "vvv" };
const char* m3[5] = { "lkkl", "kkk", "lkkl", "skl", "jkljkl" };
const char *m4[5] = { "one", "two", "three", "four", "five" };

I just want to represent the data above in a single array where each element represents one of the array above.我只想在一个数组中表示上面的数据,其中每个元素代表上面的数组之一。 like array of array of pointers to cons char structure(corrected me please if this saying wrong) I try to do the following but it doesn't work像指向 cons char 结构的指针数组(如果这句话错了,请纠正我)我尝试执行以下操作,但它不起作用

char *(const char* exm[5])[4] = { &m1, &m2, &m3, &m4};

Help?帮助?

Remember that arrays naturally decays to pointers to their first element.请记住,arrays 自然衰减为指向其第一个元素的指针。 For an array of pointers, that becomes a pointer to a pointer, ie const char ** for your arrays m1 to m4 .对于指针数组,它成为指向指针的指针,即const char **用于您的 arrays m1m4

So you need an array of pointer to pointers:所以你需要一个指向指针的数组:

const char **exm[] = { m1, m2, m3, m4 };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM