开发者

How do I pass in a multidimensional int array into a function in C?

开发者 https://www.devze.com 2023-02-09 15:14 出处:网络
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])

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

精彩评论

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