Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the effect of calling free() on a null pointer ?

  • A.The program crashes
  • B.Nothing happens; it is safe
  • C.The heap is corrupted
  • D.A compilation error occurs

Answer: B

Correct answer: Nothing happens; it is safe

The C standard requires free(NULL) to do nothing at all. This is why cleanup code can call free() on a pointer without first testing it, provided the pointer was set to NULL when no allocation was made.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.