analyze each program and figure out what is wrong with the memory management in the code and how to fix the code. #include #include #include #include // Hint: If you run this program repeatedly,...


analyze each program and figure out what is wrong with the memory management in the code and how to fix the code.


#include
#include
#include
#include


// Hint: If you run this program repeatedly, with ever-larger numbers as input,
// eventually something (slightly) unexpected should happen.
int
main(int argc, char *argv[])
{
if (argc != 2) {

fprintf(stderr, "usage: broken2 \n");

exit(1);

}

int size = atoi(argv[1]);
int *p;
p = malloc(size*sizeof(int));
for (int i = 0 ; i < size;="" i++)="">
p[i] = i;
}
int *q;
q = malloc(sizeof(p));
for (int i = 0 ; i < size;="" i++)="">
q[i] = p[i];
}


free(p);
free(q);
return 0;
}




Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here