I want to fill in a dynamically created array once only at the top of my function. Then every function after can only access the contents but not modify it. What is the correct way:
const double *pt = malloc(sizeof(double)*num);
OR
double *pt = malloc(sizeof(double)*num);
void f(const double array[], ...);
When I use the second method, do I have to cast pt to const?
The first method will not work because you won’t be able to populate the array in the first place (since you have declared it
const).The second method will work if you have already populated the array before calling
f().