Can a pointer to a multidimensional array in C be written simply as:
double *array;
Where arrayis an n by n matrix?
And then can I access the element in row i, column j, by array[i][j]?
Or is there such thing as a double pointer?
Can a pointer to a multidimensional array in C be written simply as:
double *array;
Yes.
Say you have M x N array. You can use:
double* array = malloc(M*N*sizeof(*array));
Then, you can access the elements by using:
size_t getArrayIndex(size_t m, size_t n, size_t M)
{
return (m*M+n);
}
double getArrayElement(double* array, size_t m, size_t n, size_t M)
{
return array[getArrayIndex(m, n, M)];
}
Can a pointer to a multidimensional array in C be written simply as:
double *array;
That could be something that is used to represent an array, when handing it over to a function! A C array is then only represented by a pointer to its first element. How these elements are organized internally is up to you; making sure you don't use indices that are actually outside the array, too.
Or is there such thing as a double pointer?
Of course; double ***ndim_array is perfectly valid. However, you could also use multidimensional arrays like double [][][].
(Thanks to all the contributors in comments!)
double[][] actually having to be read as "an array of arrays", ie. a pointer to a pointer.
**, but it's not the same as a[][]at all.array[rows * columns](or allocate memory for) and index by[row * columns + col]