Returning from the function BEFORE you free the Array doesn't really make much sense. It might "work", but it doesn't do all that you want it to.
Code:
#include <stdio.h>
#include <stdlib.h>
double* makeAnArray(double size);
int main (void)
{
double *anArray;
char throwaway;
int size = 0;
int k;
printf("Please enter the size of the array: ");
fflush(stdout);
scanf("%d", &size);
scanf("%c", &throwaway);
anArray = makeAnArray(size);
for (k = 0; k < size; k++)
{
printf("%f ", anArray[k]);
}
printf("\n");
fflush(stdout);
free(anArray);
getchar();
return 0;
}
double* makeAnArray(double size)
{
double* array;
array = calloc(size,sizeof(double));
return array;
}
And here's the output:
Code:
Please enter the size of the array: 10
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
I'm begging you, look at the red highlights HARD. These are the things you need to study.