使用指向数组数组的指针声明和初始化数组

时间:2022-02-20 21:16:58

In the context of this question, I came up with the following code

在这个问题的上下文中,我提出了以下代码

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};

to store pointers to arrays of arrays (2-tuples) in an initialized list. However, I failed to write equivalent code without using a typedef. What would the correct syntax for this look like?

在初始化列表中存储指向数组(2元组)数组的指针。但是,我没有使用typedef编写等效代码。这个的正确语法是什么样的?

1 个解决方案

#1


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};

Keep the typedef.

保持typedef。

#1


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};

Keep the typedef.

保持typedef。