← Quiz: Dynamic Memory: all 10 questions
Quiz: Dynamic Memory · Question 9 of 10
What happens if you call free(p) twice on the same pointer?
What happens if you call free(p) twice on the same pointer?
- A.The second call is ignored
- B.The memory is freed more completely
- C.Undefined behaviour: the program may crash or corrupt the heap
- D.It returns an error code
Answer & explanation
Correct answer: Undefined behaviour: the program may crash or corrupt the heap
Setting p = NULL after free makes a second free(p) harmless, because free(NULL) does nothing.
Can you get the rest right without peeking?
Take the timed Quiz: Dynamic Memory quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →