I\'m asking this because my program have two functions to multiply matrices, they multiply only 4x4 and 4x1 matrices. The headers are:
double** mult4x1(doub
No.
A double**
is a pointer to a pointer to a double (double*
).
So actually it should be created like this (note the extra * in the first malloc sizeof()):
double** result = (double**) malloc(sizeof(double*)*4);
for (int i = 0; i < 4; i++) {
result[i] = (double*) malloc(sizeof(double)*4);
}
So in memory it would look like this:
[] -> { d,d,d,d }
[] -> { d,d,d,d }
[] -> { d,d,d,d }
[] -> { d,d,d,d }
There are 4 buffers that hold 4 doubles, but are not continuous.
While your double[4][4] is a continuous buffer in memory, like this:
{ { d,d,d,d } { d,d,d,d } {d,d,d,d} {d,d,d,d} }