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
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.