CJCoding With Joseph
15free / daySign inCreate account

Free It, Then NULL It

Read an integer n. Allocate n ints on the heap and set element i to (i + 1) * 10. Then print exactly five lines:

- "First: <element 0>"
- "Last: <element n - 1>"
- "Is NULL before free: <1 or 0>"
- then free the block, set the pointer to NULL, and print "Is NULL after free: <1 or 0>"
- then call free on the now-NULL pointer a second time and print "Freed twice safely"

For the input:

3

the output is exactly what is shown in Expected Output.

Print the NULL comparison, never the address itself.

Free the memory you allocate before the program ends — this question checks for memory leaks.

Expected Output:

First: 10
Last: 30
Is NULL before free: 0
Is NULL after free: 1
Freed twice safely

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
3\n
This input is automatically fed to your program's stdin
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.