How Pointer of Multi-Dimension Arrays Work in C

后端 未结 3 675
星月不相逢
星月不相逢 2020-12-10 08:40

I\'m experimenting with the concept of pointer to multi-dimension array in C. Suppose I want to process a multi-dimensional array via a function. The code kinda looks like t

3条回答
  •  天命终不由人
    2020-12-10 09:07

    This won't work:

    void proc_arr(int ***array)
    {
        (*array)[0][1] = 10;
    }
    

    Because, behind the scenes the compiler will have to change this into an offset into memory relative to the start of the array. That means it needs to know the dimensions of the array. You have not declared those in the function signature.

提交回复
热议问题