Search code examples
arrayscansi-c

How to put parameters(2nd grade array) to sub() ,,...void func( int* Array2nd)


void HowToPutParameters( XXXXXX)  // how to put parameters in XXXXXX
{
    array[0][0]=5; 
}    
void main()
{    
    int array[2][2]={{1,2},{3,4}};  
    HowToPutParameters(&array[0][0]);  // &array[0][0] is correct or &array[0]
}

// I wana put this array to HowToPutParameters;

// 1.I am not sure "&array[0][0] or &array[0]" are correct,The compiler seems identify;

// I've tried void HowToPutParameters(int *array ) ==> compile failed

// I've tried void HowToPutParameters(int *array[][] ) ==> compile failed

// My compiler is MPLAB X IDE V1.8 , Chip is Microchip>PIC32MX795F512


Solution

  • If you want use pass two dimensions array params,use:

     void func(int (*a)[2]);// tell the function the first dimension size!
     func(array);
    

    It is the same as:

     void func(int a[][2]);
     func(array);
    

    If you pass &array[0][0], it means you pass a pointer point to a int.

    void func(int *element);