Possible Duplicate:
Passing multidimensional arrays as function arguments in C
In C, if I want a function to receive a 2-D array, can I use * notation for the function parameter
int (int my2dary[][10]); //This is what I do not want.
Possible Duplicate:
Passing multidimensional arrays as function arguments in C
In C, if I want a function to receive a 2-D array, can I use * notation for the function parameter
int (int my2dary[][10]); //This is what I do not want.
Yes, you pass a pointer to an array of int
int func(int (*my2dary)[10]);
and you call it
int a[5][10];
func(a);
Although, func
doesn't know how many elements are in my2dary
, so you must give a number too
int func(int n, int (*my2dary)[10]);
and call
int a[5][10];
func(5, a);
See How to interpret complex C/C++ declarations or The ``Clockwise/Spiral Rule''.
如果您的问题是您在编译时不知道数组的大小,您可能需要:
int func(int *array, int size)
{
int n,m;
...
array[m*size+n]; /* = array[m][n] if in the caller: int array[x][size]; */
}
可选地(并且很可能您需要)您可以传递第二个大小参数 (x) 以便能够测试数组边界