0

I have a function which takes a 2d-array as an argument. Then I have a 3d-array e.g. temp[5][100][100]. I want to pass the 2d portion of this array to the function. How can I do this?

int inteference_sets(int array[][],int array_size,int max_channel){
     //function codes
}
int main(){
    int k;

    int temp[5][100][100];
    for(k=1;k<=4;k++){
       interference_sets(temp[k], , ) //this is how the program intends to work
    }
 }

Is it possible? If yes, then how?

3
  • By "second portion" I assume you mean any of the five 100x100 partitions, by reference/address. Commented Apr 25, 2013 at 15:04
  • yeah.. i think you got me right ! Commented Apr 25, 2013 at 15:08
  • Then you chose... wisely. Commented Apr 25, 2013 at 15:09

1 Answer 1

2
#define DIM1 100
#define DIM2 100

int inteference_sets(int (*array)[DIM2], int array_size, int max_channel)
{
     int row, col;

     for( row = 0; row < array_size; row++ )
     {
         for( col = 0; col < DIM2; col++ )
         {
             int value = array[row][col];
             //function codes
         }
     }
} 

int main()
{
    int k;

    int temp[5][DIM1][DIM2];

    for(k=1;k<=4;k++)
    {
       interference_sets(temp[k], DIM1, ) //this is how the program intends to work
    }
 }
Sign up to request clarification or add additional context in comments.

1 Comment

+1. Also note that unlike C++, almost all reasonable intelligent C implementations support VLAs (variable length arrays) including VLA parameters. This allows you to specify at runtime what the compiler would normally require constants to deduce. See it live for an example. Nice answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.