calloc Proves the Bytes Are Zero
mediumQuestion 452Read an integer n. Use calloc to allocate n ints, then print two lines:
- "Before:" followed by every element, each preceded by a single space - then store i * i in element i, and print "After:" followed by every element the same way
For the input:
4
the output is exactly what is shown in Expected Output.
Format: the label, then one space before each number, and no trailing text.
Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected output
Before: 0 0 0 0 After: 0 1 4 9
= 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.