This code:
bool* myArray[2];
int N;
doesn't declare a 2-dimensional array but an array of pointers. This is an important difference because 2-dimensional arrays are not arrays of pointers to arrays -- they are just stored contiguously, like 1-dimensional arrays are (one "row" after the other).
So, as you state you cannot change the declaration, let's instead explain what you need for an array of pointers. With your declaration, you declare exactly 2 pointers, so N
can only mean the "second dimension" as in the number of elements in the arrays those pointers point to. With this declaration, you can have 2 times an array of N
bools. Allocating them would look like this:
myArray[0] = calloc(N, sizeof(bool));
myArray[1] = calloc(N, sizeof(bool));
There's no need to allocate space for myArray
itself, with your declaration, it already has automatic storage.