Dereferencing Arrays

Hi everybody.
Keeping my fingers crossed here, hoping that someone can shed some light
on this problem for me.
I have a function which accepts a 2D array
of 9x9 dimentions.

1
2
3
  int array[9][9];

  int function(int a[][9])


And i send the array to the function like so:

 
   function(array);


Now, suppose I need to send a 3D array to the same function.
An array of dimentions 5x9x9

 
   3dArray[5][9][9];


How do I send it so that my function iterates through those 5 9x9 arrays?

Thank you.
closed account (D80DSL3A)
Your function won't iterate over 5 9x9 arrays since it was written to work with just one.

You can send the 5 9x9 arrays to it one by one though, and iterate over 5 calls to the function (if that's useful). Here's an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

int F( int a[][9] )// find and return the sum of all 81 elements
{
    int sum = 0;
    for( unsigned i=0; i < 9*9; ++i )
        sum += a[i/9][i%9];
    return sum;
}

int main()
{
    int arr3D[5][9][9];

    // initialize the element values
    for( unsigned i=0; i < 5*9*9; ++i ) arr3D[0][0][i] = i;// 0-404
    
    // print the sum of each 9x9 array of values
    for( unsigned i=0; i < 5; ++i )
        cout << "sum = " << F( arr3D[i] ) << endl;

    cout << endl;
    return 0;
}


Output:
sum = 3240
sum = 9801
sum = 16362
sum = 22923
sum = 29484
Thank you
Now I will not be trying to do something that's not doable so,
it's useful.
Topic archived. No new replies allowed.