简体   繁体   中英

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; 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)
{ /* ... */ }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM