在C中,我需要静态预分配一个数组数组,每个数组都与一个不同的字符串数组关联。下面的代码是否会这样做:C数组的字符串
struct number_and_strings {
int nnn;
char **sss;
}
static struct number_and_strings my_list[] = {
{12, {"apple","banana","peach","apricot","orange",NULL}},
{34, {"tomato","cucumber",NULL}},
{5, {"bread","butter","cheese",NULL}},
{79, {"water",NULL}}
}
为什么不试试看? –
我担心的是它看起来会起作用,但由于对指针的一些误解,我最终会吞噬或泄漏内存。 –
指针将指向数据段中的内存位置。没有泄漏。 –