double**
is a pointer to pointer. Of course the (outer) pointer could point to some array, too:
double* array[7];
double** pointer = array;
Now each of the pointers in array
could point to other arrays as well:
double valueArray[12]
double* pointerArray[10];
double** pointer = array;
pointer[0] = valueArray; // equivalent to pointerArray[0] = ...
Two-dimenstional arrays are not arrays of pointers, though, they are arrays of arrays, and pointer to first element is of different type:
double array[10][12];
double(*pointer)[12] = array;
Trying to cover arbitrary size matrices produces some trouble, though:
struct Matrix
{
size_t n;
double(*data)[n]; // you cannot exchange arbitrary pointers,
// you need a compile time constant!
};
Be aware that this is different from VLA in function parameters, where you could have
void f(size_t n, int(*data)[n]);
Then it looks as if you get pretty much into trouble already with the bit of code you presented:
void someFunction(Matrix* m)
{
double array[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
m->data = array; // assuming you meant m instead of A
// and you did adjust the pointer type already appropriately
}
array
has local storage duration and will be destroyed as soon as you return from the function, resulting in a dangling pointer in m
and in undefined behaviour, if you dereference that pointer after returning from function.
So you would need to malloc
an array of sufficient size instead. But don't forget to free it again then, too!
So if you don't want to go the pointer to pointer way:
double** array = malloc(sizeof(*array) * n);
array[0] = malloc(sizeof(**array) * n);
// ...
which would allow for the m->data[x][y]
syntax, then you should stick to the one-dimensional array approach:
struct Matrix
{
size_t n;
double* data;
};
and maybe some accessor function:
double get(struct Matrix* m, size_t row, size_t column)
{
return m->data[row * m->n + column];
}
which would get around the double pointer indirection and thus be faster (actually, that's exactly the same calculation that occurs under the hoods with a true two-dimensional array, i. e. not the pointer to pointer variant).