I have created a double int pointer in main and called a function where I allocate place for this pointer.
void foo(int **array)
{
int i, j;
array = (int **)malloc(sizeof(int *)*(100)); //rows
for(i=0; i<100; i++)
array[i] = (int *)malloc(sizeof(int)*(50)); //cols
array[0][0] = 10;
}
and in main I have just these lines;
int** array;
foo(array);
printf("%d \n", array[0][0]);
As a result I get a segmentation fault. Since I am passing a pointer and it is allocated in foo
method, does it mean that in main
method it is not allocated? How can I solve it without making foo
function to return a double pointer?