🎙 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 4 of 10

After free(p);, what should you do to avoid a dangling pointer?

After free(p);, what should you do to avoid a dangling pointer?

  1. A.free(p) again
  2. B.Set p = NULL
  3. C.Print *p
  4. D.Nothing
Answer & explanation

Correct answer: Set p = NULL

Setting p to NULL prevents accidental use; free(NULL) is harmless.

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 →