← 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?
- A.free(p) again
- B.Set p = NULL
- C.Print *p
- 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 →