I understand that modern C standards lets me allocate a block of memory to a 2d array as follows:
size_t rows, cols;
// assign rows and cols
int (*arr)[cols] = malloc(sizeof(double[cols][rows]));
But is there a way of allocating a block of memory to a 2d array after a declaration? E.g. I have an external variable declared elsewhere I would like to allocate memory to:
size_t rows, cols;
extern int **arr;
//Malloc block to 2d array
I know it's possible to, for example, use a single index in place of 2 [i][j] -> [i*rows + j] but I'm wondering if I can retain the 2 indices?