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!