Question: This C program crashes after a couple of loops. What is wrong with it and how can it be fixed? (theoretically the program should run

This C program crashes after a couple of loops. What is wrong with it and how can it be fixed? (theoretically the program should run forever)

#include

#include

#include

int main(void) {

int i, j = 0;

while(1) {

int size = 10000000;

int *a = (int *) malloc(size * sizeof(int));

for(i = 0; i < size; i++)

a[i] = i;

printf("repetition %d ", ++j);

}

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!