What does realloc(p, 0) do when p is a valid block returned by malloc?
Correct answer
B. Implementation-defined: it may free p and return NULL, or return a small block
19 views
B. Implementation-defined: it may free p and return NULL, or return a small block
19 views
With a size of zero, realloc has implementation-defined behaviour: the block may be freed and a null pointer returned, or the implementation may return a unique non-null pointer that can be passed to free. Portable code tests for zero explicitly and calls free instead. Note that a failed realloc with a nonzero size returns NULL and leaves the original block untouched and still valid.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is B? Ask here and get an explanation.