Passing a 2D array in a function in C program

后端 未结 3 1202
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-06 11:53

Below program (a toy program to pass around arrays to a function) doesn\'t compile. Please explain me, why is the compiler unable to compile(either because of techni

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 12:20

    In C99, as a simple rule for functions that receive "variable length arrays" declare the bounds first:

    void print2(int n, int m, int array[n][m]);
    

    and then your function should just work as you'd expect.

    Edit: Generally you should have a look into the order in which the dimension are specified. (and me to :)

提交回复
热议问题