I tried the following two approaches. When I test it in a small program, both seem to work. But it could be possible that memory is coming from the OS which will be zeroed by default.
Approach1:
int n_var = 1000;
double *vars = malloc(n_var*sizeof(*vars));
if(!vars) die("Memory error.");
memset(vars, 0, n_var*sizeof(*vars));
Approach2:
int n_var = 1000;
double *vars = calloc(n_var, sizeof(*vars))
if(!vars) die("Memory error.");
Could anybody confirm if the above are correct?
Theoretically, nothing mandates that the representation of 0.0 is all bit clear and thus you should initialize explicitly.
Practically, the most common double formats have this property and both ways will works.