double (*XX)[2]
is a pointer to an array with two double
elements.
double *XX[2]
is a pointer to an array with two double *
elements.
malloc
is for dynamic memory allocation, for example:
char array_stack[2]; // 2 chars allocated on the stack (no need for free())
char *array_heap = malloc(2 * sizeof(char)); // 2 chars allocated on the heap
// later...
free(array_heap); // heap memory must be freed by user
FYI:
char array_stack[2]; // this is nevertheless a pointer
char *array = array_stack; // this works, because array_stack is a pointer to a char
For more information about the stack and heap: Stack vs Heap
double *XX[2] = malloc(2*N*sizeof(double));
Does not work because it expects two elements as initializer. For example:
double _1, _2;
double *XX[2] = {&_1, &_2};
If you want do to this with malloc you need to change it to a pointer to an array with double pointers like this:
double **XX = malloc(...);