Question #33126

how to solve memory leaks in c

Expert's answer

In case you don't know the memory amount the program needs, dynamic allocation of memory should be used.

Thus, instead of static memory allocation:


int array[10];


you should use dynamic allocation:


int *array = NULL;
array = malloc(n*sizeof(int));


where n is size of an array determined while executing the program.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS