🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.The second call is ignored
  2. B.The memory is freed more completely
  3. C.Undefined behaviour: the program may crash or corrupt the heap
  4. 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 →