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
Get step-by-step solutions from verified subject matter experts
