# pass 3D array

Printable View

• 07-24-2005
gnncj
pass 3D array
For 2D array, we can pass the array to other function like:
Code:

```int array[5][10]; ... func((int *)array, 5, 10); ... ... int func(int *array, int x, int y) {     *(array + y * 0 + 8) = 1000;  /*change array[0][8]*/     *(array + y * 1 + 8) = 2000;  /*change array[1][8]*/ }```
I' m wondering how we can pass a 3D array...
• 07-24-2005
Salem
> For 2D array, we can pass the array to other function like:
Since your attempt at 2D is wrong, 3D will be hopeless.

If you have
int array[5][10];

The prototype for a function is
void func ( int array[5][10] );

A call to this function would be
func ( array );

And the implementation would be
Code:

```void func ( int array[5][10] ) {   array[0][0] = 0; }```
Notice how simply copy/pasting the array into the function parameter is all you need to do.
Also notice the complete lack of any * or & operators anywhere in the code.

Pedantically, you can reduce
void func ( int array[5][10] );
to
void func ( int array[][10] );
since C doesn't need to know the size of the first dimension of the array.
• 07-24-2005
gnncj
What if we don't know exactly the size of array we gonna pass to func()?
How can we create a func() which can accept any size of array?
• 07-24-2005
Salem
http://www.eskimo.com/~scs/C-faq/q6.19.html

int a[5][10];
int b[100][10];
Can both be passed to void func ( int array[][10] );