[英]How do I pass in a multidimensional int array into a function in C?
As above, say I have a 3 dimensional array, a[][][], and I want to pass this to a function; 如上所述,假设我有一个3维数组a [] [] [],我想将其传递给函数; how should I declare the function parameter?
我应该如何声明功能参数?
void function1(int array[][3][4])
{
...use array here...
}
void function2(void)
{
int array[20][3][4];
...load array...
function1(array);
}
Just declare a triple pointer 只需声明一个三重指针
int functionName(int*** arrayPtr, int x, int y, int z){
return arrayPtr[z][y][x];
}
I would send a pointer to pointer to pointer with all dimensions. 我将发送一个指向所有尺寸的指针的指针。
void foo(int ***ar, size_t l, size_t m, size_t n)
{ /* ... */ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.