0

Let's say I have a declaration of a two-dimensional array:

int array[4][2] = { { 0, 2 }, { 1, 8 }, { 2, 4 }, { 3, -10 } };

I have a function that takes a two-dimensional array as a parameter:

void sort( int **, int );
...
void sort( int **array, int arraylength ){
...
}

I pass the array to the function by value, like so:

sort( array, 4 );

I get the following error:

frequency.c:53:8: warning: passing argument 1 of 'sort' from incompatible pointer type [-Wincompatible-pointer-types]
  sort( array, 4 );
        ^~~~~

How is the type incompatible? My understanding is that all array variables are treated as pointers, so I'm just passing an int pointer pointer to a function that takes an int pointer pointer as a parameter, effectively passing the data in the array by reference. The only difference is that the function prototype uses array notation for the parameter while the declaration of the array uses the regular static array notation. Are statically declared arrays somehow different from dynamically declared arrays?

  • 2
    type of `array` isn't `int**`. `void sort( int dim, int (*array)[dim], int length);`.. `sort(2, array, 4 );` – BLUEPIXY Feb 20 '17 at 17:09
  • "My understanding is that all array variables are treated as pointers" This is a common misconception, but no there is more to it than it first meets the eyes. You also use the terms "statically declared arrays" and "dynamically declared arrays" wrong. – bolov Feb 20 '17 at 17:30

0 Answers0