-1

I am curious how the best programmers in the world allocate memory for a 2d array. Any tips and advice will be much appreciated.

PS I am just a student trying to learn.

1 Answers1

3

Use array pointers

{
    size_t rows = 10;
    size_t cols = 50;

    int (*array)[cols] = malloc(rows * sizeof(*array));

    /* ... */

    free(array);
}
0___________
  • 60,014
  • 4
  • 34
  • 74