Grow a Heap Array with realloc
mediumQuestion 453Read an integer n, then n integers. Allocate room for n ints and store them, then print "Size: <n>".
Next read an integer m, grow the SAME block to n + m ints with realloc, read m more integers into the new space, and print "Size: <n + m>".
Finally print a line "Values:" followed by every element, each preceded by a single space.
For the input:
3 1 2 3 2 4 5
the output is exactly what is shown in Expected Output.
The first three values must survive the resize.
Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected output
Size: 3 Size: 5 Values: 1 2 3 4 5
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.