I try to dynamically allocate one dimension of a two dimensional array. The array is declared as follows:
uint16_t coord[][2];
I only need to allocate the rows, the number of coordinates.
Over google I found enough code to allocate both of the dimensions, starting from:
uint16_t **coord;
I am not sure if I can still declare the array as above. Do I need to do:
uint16_t *coord[2];
or not?
I also need to return the array (the pointer to it) from the allocating function so other functions can access the array like this:
foo = coord[4][0];
bar = coord[4][1];
What’s the correct way to return the allocated array?
According to the clockwise/spiral rule, the following declaration:
is an array of two pointers, which seems to be not what you want. However you can use this instead:
You can allocate memory for it like this:
Now you can access it as a normal multi-dimensional array: