Create 2D array by passing pointer to function in c

后端 未结 3 1117
情书的邮戳
情书的邮戳 2021-01-20 04:55

So I read dozens of examples of passing an 2D array pointer to function to get/change values of that array in function. But is it possible to create (allocate memory) inside

3条回答
  •  -上瘾入骨i
    2021-01-20 05:05

    Yes, an array can be initialized this way. As long as you pass a pointer, the memory address should remain the same. So, if you assign anything to the pointer it will valid.

    Think of an a[] as a* pointer to the first element

    a [][] will be a** pointer to a pointer of the first element or a pointer to the first array (first row of a table)

提交回复
热议问题