I'm attempting to allocate space for 100 doubles, check if the allocation was successful, and then deallocate the space. After that I'd like to use the original allocated space to write 100 random numbers to it and then sort them using qsort
.
Here's the code I have to far
#include <stdio.h>
#include <stdlib.h>
int main()
{
double *num = (double*) malloc(sizeof(double) * 100);
printf("%lf", *num);
realloc(num, 0);
return 0;
}
When I attempt to print *num
, it gives me 0.00000
which seems wrong. I get the warning
warning: ignoring return value of function declared with
'warn_unused_result' attribute [Wunused-result] realloc(num, 0);
when compiling the program. I'm still unsure on how to make this work with an array.