When using realloc is the memory automatically freed? Or is it necessary to use free with realloc? Which of the following is correct?
//Situation A
ptr1 = realloc(ptr1, 3 * sizeof(int));
//Situation B
ptr1 = realloc(ptr2, 3 * sizeof(int));
free(ptr1);
ptr1 = ptr2;
Neither is correct. realloc() can return a pointer to newly allocated memory or NULL on error. What you should do is check the return value: