Not a full answer as solution is already given by savageGoat, but some additional hints on writing better C code:
double *arr;
arr = (double *)calloc((3), (unsigned)(sizeof(double)));
Please skip all those unnecessary parentheses, they just make the code harder to read. Assignment can occur directly with declaration, but that's rather a matter of personal preference:
double *arr = (double *)calloc(3, (unsigned)sizeof(double));
The cast to unsigned int
is unnecessary, sizeof
already evaluates to an unsigned type (size_t
). Actually the cast even is technically wrong, as you might cut off size information that way: Imagine 16-bit unsigned int and a huge struct with more than 65k bytes – admitted, that's rather of theoretical nature, but still the cast is not correct.
Additionally you are assigning values afterwards anyway, so zero-initializing, which calloc
does, is just unnecessary ballast, so prefer malloc
in this case:
double *arr = (double *)malloc(3 * sizeof(double));
Now there's still a memory leak left! Sure, the OS will clean up that for you, as the process terminates anyway, but get used right from the start to considering to free any dynamically allocated memory right at the point of doing so (or even before...). Otherwise you will run into memory leaks on longer running processes.
Even better: Allocate the array on the stack, if not too large for; in this case, you even can initialize it right away:
double arr[] = { 10.0, 20.0, 30.0 }; // size is calculated by compiler
Finally, in this case you do not need the array at all:
printf("%f %f %f
Actually, you don't even need a dynamically allocated array at all:
printf("%f %f %f", 10.0, 20.0, 30.0);
Just make sure to use the correct literals (10, 20, 30
would provide three int
values, which would be accepted as well by the compiler, but provoke undefined behaviour as not matching the required type for the format specifiers).