(Solved) : Use Realloc Enlarge Existing Block Dynamic Memory 1 Make Copy Task1c Source File Name Task Q30738220 . . .
Use realloc to enlarge an existing block of dynamic memory 1. Make a copy of your task1.c source file and name it task3.c. 2. Extend the code by making use of the realloc function to double the size of the t1 dynamic array (from 5 to 10 integers). Add your code at the end of the main function but above the call to free Assign the result to a new t3 pointer as follows: int t3realloc (tl, /new size calculation ); 3. Add a suitable control statement to test the value of t3 and verify the memory reallocation was successful. As with malloc/calloc, realloc will return NULL such cases, the original memory contents will be unaffected. if the request failed. In 4. If reallocation succeeds: o set the value of all new elements to 100 o print the contents of the expanded t3 array using the print function. o add suitable code to ensure the memory is deallocated. Recall that realloc may move the block during reallocation so the original t1 pointer may be invalid. A good strategy is to update the address of t1 with the address of t3 so they both point to the same reallocated block How would this affect calls to free? Use Valgrind if necessary to confirm you have freed the memory (remember to use the -g gcc option). 5. Compile and run the program. The output should resemble the following with the original values form Task 1 untouched: $/task3 01 0  2 [31 3 [41 4 01 0  2 [31 3 [5) 100  100 71 100 [8 100 91 100 Show transcribed image text
. . .