malloc-ating multidimensional array in function

前端 未结 7 1851
傲寒
傲寒 2020-12-10 22:28

I\'m trying to allocate a 2d array in a C program. It works fine in the main function like this (as explained here):

#include 
#include 

        
7条回答
  •  没有蜡笔的小新
    2020-12-10 23:11

    C is actually always pass by value, so when you pass in 'grid' you are passing in a value and the function is modifying its own local copy. Try passing in '&grid' instead and modify malloc2d appropriately.

提交回复
热议问题