Dynamic memory is allocted in heap in the program.
So code to allocate dynamic memory in the heap as mentioned in question is like:
double *values;
values = malloc(20 * sizeof(double));
So now one can put values in it by using simply values[0], values[1]....values[19]
To free the dynamically allocated memory in heap one can use free() function.
Code to free the memory dynamically allocated in the above code is like:
free(values);
values=NULL;
Assigning Null to the pointer after the deallocation is not necessary but it is a good practice.
Get Answers For Free
Most questions answered within 1 hours.