ProgrammingVery hard

What is the effect of realloc(p, 0) when p came from malloc, in the C standard's terms?

  1. A. It always frees p and returns NULL
  2. B. It always keeps p and returns it unchanged
  3. C. It is a compile error
  4. D. The behaviour is implementation-defined: the call may free p and return NULL, or return a unique pointer

Correct answer: D. The behaviour is implementation-defined: the call may free p and return NULL, or return a unique pointer

C99 made realloc with zero size implementation-defined, so portable code should not rely on either result. The option that always frees is not guaranteed.

More C Programming questions

Exams that ask this topic