2D-array as argument to function

后端 未结 6 893
無奈伤痛
無奈伤痛 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:21

    Because when you pass an array, it decays to a pointer, so excluding the outer-most dimension is ok and that's the only dimension you can exclude.

     void Foo(int bar[][SIZE]) 
    

    is equivalent to:

     void Foo(int (*bar)[SIZE]) 
    

提交回复
热议问题