![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
dakarn
I switched up my code a little bit but my understanding may be faulty here:
A = (double **)calloc(16, sizeof(double *));
Allocates enough memory for 16 doubles?
No, it allocates 16 rows (that don't yet have any memory in it).
Code:
for(row=0;row<4;row++)
{
A[row] = (double *)calloc(4, sizeof(double *));
if(A[row]==NULL)
{
printf("(main) calloc failed in double *A[]\n");
exit(4);
}
}
allocates memory for 4 doubles for each row of 4?
Thanks for the replies tabstop!
It allocates memory for four pointers-to-double, not four doubles. (This may be enough memory, but is not guaranteed to be.)