C question
Hi,
I am passing a double pointer to a function to allocate a double array and initialise the array inside the function with lets say 10.10;
I do the following but get segmentation fault when I access the array in main;
void function(double **array, int size){
*array = (double*) malloc(size * sizeof(double));
int i;
for(i=0;i<size;i++){
*array[i] = 10.10;
}
}
int main(){
double *array = NULL;
function(&array,20);
printf("array[0] = %lg\n",array[0]);// here is where I get segmentation fault
}
Any help ?
double*is a) unnecessary, and b) wrong, because what you really have there isdouble**