I am new to C language and I try to write function to allocate memory for 2d array What am I doing:
void allocate(int **arr, int r, int c)
{
**arr = (int **)malloc(r*c*sizeof(int));
}
int main( void )
{
int NO_OF_COLS = 0;
int NO_OF_ROWS = 0;
scanf("%d%d", &NO_OF_ROWS, &NO_OF_COLS);
int **matrix;
allocate(matrix, NO_OF_ROWS, NO_OF_COLS);
return 0;
}
I have this warning: assignment to 'int' from 'int **' makes integer from pointer without a cast [-Wint-conversion] 8 | **arr = (int **)malloc(rcsizeof(int)); | ^
I understand that I am passing memory to 'matrix' in allocate(), but I don't understand how I can return new memory address and assign it to matrix
I try to change allocate(matrix, NO_OF_ROWS, NO_OF_COLS);
to allocate(&matrix, NO_OF_ROWS, NO_OF_COLS);
but it still doesn't work