Passing a multidimensional array
I know that for 1-dimensional arrays, I can do...
void g(int x[]) {}
void f(int a, int b)
{
int x[a];
开发者_Python百科 g(x);
}
But with code such as...
void f(int a, int b)
{
int x[a][b][4];
g(x);
}
What would the type signature of g(x) look like?
void g(int x[][b][4]) // b must be known in advance
{}
Otherwise explicitly pass b
For example:
void g(int b,int x[][b][4]){
}
int main()
{
int a=4,b=6;
int x[a][b][4];
g(b,x);
return 0;
}
You need to specify the sizes of the arrays:
void g(int x[][2][3]){
/* stuff */
}
int main()
{
int x[1][2][3];
g(x);
return 0;
}
精彩评论