开发者

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 f开发者_运维百科unction; 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)
{ /* ... */ }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜