Passing 2-D array as argument

后端 未结 6 848
误落风尘
误落风尘 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:32

    declaration of ‘array’ as multidimensional array must have bounds for all dimensions except the first So you have to give

    array[][size] //here you must to give size for 2nd or more 
    

    For passing the array in function , array is not a pointer to a pointer but it's pointer to an array so you write like this

    fun(int (*array)[])
    

    Here if you miss the parenthesis around (*array) then it will be an array of pointers because of precedence of operators [] has higher precedence to *

提交回复
热议问题