Question: 1) Where is the memory leak in this code? int main() { int *array; array=(int *)malloc(sizeof(int)*1000); for( i = 0; i < 1000; i++ )

1) Where is the memory leak in this code?

int main() { int *array; array=(int *)malloc(sizeof(int)*1000); for( i = 0; i < 1000; i++ ) array[i] = i; return 0; }

2) (a) Where is the memory leak in this code? (1 pt)

(b) How do you fix it? (2 pts)

int main() { int **array; array=(int **)malloc(sizeof(int *)*1000); for(i=0;i<1000;i++) array[i]=(int *)malloc(sizeof(int)*500); free(array); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!