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

    getchar();
}
  1. Why does this display warnings like "braces around scalar initializer"?
  2. Why do I need to initialize multidimentional arrays with more than one pointers? (if you could give me some pretty easy-to-understand explanation on this one...)
  3. If I'd want to use int matrix[3][4] instead of int **matrix...what would be a function parameter if I'd want to pass this array? int[][]?
1
  • 2
    I suggest you read comp.lang.c FAQ, especially section 6. Commented Jan 19, 2013 at 12:56

1 Answer 1

5

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. A function declaration to pass a pointer to an array 4 of int would be:

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

or

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

or

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

The three declarations are equivalent.

Sign up to request clarification or add additional context in comments.

1 Comment

Pointers are not arrays, but they point to the beginning of the array, as far as I know. But still, question 3 remains :P

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.