LearnFrenzy
Sign in Take a free test

Memory Allocation · Memory Allocation MCQ · Question 3

What does free(NULL) do in C? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

What happens when you call free(NULL)?

  • A The program crashes
  • B Nothing – it is defined to do nothing Correct
  • C It frees the last allocated block
  • D It is undefined behaviour
Correct Answer: Option B

The standard says free(NULL) has no effect. That is why setting a pointer to NULL after freeing it makes an accidental second free() harmless, and why cleanup code can free pointers that were never allocated.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Popular