2D-array as argument to function

后端 未结 6 891
無奈伤痛
無奈伤痛 2020-11-29 11:00

Why can\'t you declare a 2D array argument in a function as you do with a normal array?

 void F(int bar[]){} //Ok
 void Fo(int bar[][]) //Not ok
 void Foo(in         


        
6条回答
  •  孤独总比滥情好
    2020-11-29 11:26

    The compiler needs to know how long the second dimension is to calculate the offsets. A 2D array is in fact stored as a 1D array. If you want to send an array with no known dimensions, consider using pointer to pointers and some sort of way to know the dimension yourself.

    This is different from e.g. java, because in java the datatype also contains the dimension.

提交回复
热议问题