Hello.
Im interested in learning something about allocating memory for a 2d array.
So I have a function that does this, and it goes something like this :
short **g2D(short **arr,short row,short col)
{
short i;
arr=malloc(row*sizeof*arr);
if(!arr)
{
printf("\nMemory unavailable");
exit(EXIT_FAILURE);
}
for(i=MIN;i<row;i++)
{
arr[i]=malloc(col*sizeof*arr);
if(!arr)
{
printf("\nMemory unavailable");
exit(EXIT_FAILURE);
}
}
return arr;
}
And the function call
2darray=g2D(2darray,row,col);
I would like to know what does it mean when I use a pointer to pointer in function prototype and in function declaration, is this necessary and is there another way to allocate memory for a 2d array via function? I understand the fact that dimensions dont exist in memory.