Initializing an array with two pointers

int main() {
    int **matrix = {
        {1, 3, 2, 4},
        {3, 2, 4, 5},
        {9, 3, 2, 1}
    };

    getchar();
}

      

  • Why does this display warnings like "parenthesis around scalar initializer"?
  • Why do I need to initialize multi-pointer multidimensional arrays? (if you could give me a pretty easy-to-understand explanation on this ...)
  • If I wanted to use int matrix [3] [4] instead of int ** matrix ... what parameter to the function if I wanted to pass this array? int[][]

    ?
+3


source to share


1 answer


int **

is a pointer type, not an array type. Pointers are not arrays. Use type int [3][4]

.

You cannot pass arrays to functions, but you can pass a pointer to an array. The function declaration for passing a pointer to array 4 of int

will be:

void f(int arr[3][4]);

      

or



void f(int arr[][4]);

      

or



void f(int (*arr)[4]);

      

The three declarations are equivalent.

+5


source







All Articles