Passing 2-D array as argument

后端 未结 6 898
误落风尘
误落风尘 2020-12-31 14:03

I am trying to pass a 2-d array to a function which accept a pointer to pointer. And I have learnt that a 2-d array is nothing a pointer to pointer(pointer to 1-D array). I

6条回答
  •  无人及你
    2020-12-31 14:46

    You should at least specify the size of your second dimension.

    int array[][5] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8, 9 }, { 10, 11, 12, 13 } };
    

    There is also an error which is often repeated. To pass a 2D array as argument, you have to use the following types:

    void myFuntion(int (*array)[SIZE2]);
    /* or */
    void myFuntion(int array[SIZE1][SIZE2]);
    

提交回复
热议问题