typedefs是你的朋友:
typedef int A[2]; // typedef an array of 2 ints
A *foo(int n)
{
A *a = malloc(n * sizeof(A)); // malloc N x 2 array
// ... do stuff to initialise a ...
return a; // return it
}
Run Code Online (Sandbox Code Playgroud)
要了解typedefs 为什么有用,请考虑没有a的等效实现typedef(感谢@JohnBode为此示例提供正确的语法):
int (*foo(int n))[2]
{
int (*a)[2] = malloc(n * sizeof *a); // malloc N x 2 array
// ... do stuff to initialise a ...
return a; // return it
}
Run Code Online (Sandbox Code Playgroud)