ProgrammingModerate

Which statement about calling free on a null pointer is correct in C?

  1. A. It does nothing, so free(NULL) is safe
  2. B. It is undefined behaviour and must be avoided
  3. C. It frees the memory at address zero
  4. D. It is a compile error

Correct answer: A. It does nothing, so free(NULL) is safe

The standard defines free(NULL) as a no-op. This makes cleanup code simpler, since no test is needed.

More C Programming questions

Exams that ask this topic