I would like to call a function with some arguments and within this function allocate a 2D array and then pass the pointer to it back to main. this is not the actual code I'm using but a simplified "toy" code to explain what I'm trying. I am getting a segfault and I don't quite understand why. I've done stuff like this before and I thought this would work. any idea what I'm screwing up?
void func(int val, int ** array);
int main()
{
int **array;
int i = 2;
func(i,array);
// do some stuff with info from array[i][2]
free(array);
}
void func(int val, int **array)
{
// do some calculation here to find the row size for array
array = malloc(row_size*sizeof(int *));
for (i = 0; i < row_size; i++)
array[i] = malloc(2* sizeof(int));
// fill the 2d array with some values
}
malloc(sizeof(int) * rows * columns)