Question

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

Was it helpful?

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);

OTHER TIPS

Like this, in your code you are only passing a pointer to an int element of the array, not the array itself.

void HowToPutParameters(int* element)

And you should always use int main instead of void main.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top