← Back to Pointers
Question 455
Factory Function Returns a Heap Array
Factory Function Returns a Heap Array
Writemake_squares(n)so it returns a heap array of n ints where element i holds (i + 1) * (i + 1). Then in main: read n, call make_squares, print every value on its own line, print "Total:<t>" where<t>is their sum, and free the array in MAIN. For the input: 4 the output is exactly what is shown in Expected Output. Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected Output:
1 4 9 16 Total: 30
= newline. The output ends with a newline — 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.