使用指向数组数组的指针声明和初始化数组
Declaring and initializing an array with pointers to arrays of arrays
在this question的背景下,我想出了下面的代码
typedef char Tuple[2];
Tuple test1[2] = {{1,2},{1,2}};
Tuple test2[3] = {{1,2},{1,2},{1,2}};
Tuple test3[4] = {{1,2},{1,2},{1,2},{1,5}};
Tuple* all[3] = {test1, test2, test3};
在初始化列表中存储指向数组数组(二元组)的指针。但是,如果不使用 typedef
,我无法编写等效代码。正确的语法是什么样的?
char test1[2][2] = {{1, 2}, {1, 2}};
char test2[3][2] = {{1, 2}, {1, 2}, {1, 2}};
char test3[4][2] = {{1, 2}, {1, 2}, {1, 2}, {1, 5}};
char (*all[3])[2] = {test1, test2, test3};
保留 typedef。
在this question的背景下,我想出了下面的代码
typedef char Tuple[2];
Tuple test1[2] = {{1,2},{1,2}};
Tuple test2[3] = {{1,2},{1,2},{1,2}};
Tuple test3[4] = {{1,2},{1,2},{1,2},{1,5}};
Tuple* all[3] = {test1, test2, test3};
在初始化列表中存储指向数组数组(二元组)的指针。但是,如果不使用 typedef
,我无法编写等效代码。正确的语法是什么样的?
char test1[2][2] = {{1, 2}, {1, 2}};
char test2[3][2] = {{1, 2}, {1, 2}, {1, 2}};
char test3[4][2] = {{1, 2}, {1, 2}, {1, 2}, {1, 5}};
char (*all[3])[2] = {test1, test2, test3};
保留 typedef。