realloc is conceptually equivalent to
malloc + memcpy + free on the other pointer.
If the size of the space requested is zero, the behavior of
realloc is implementation-defined. This is similar for all memory allocation functions that receive a
size parameter of value
0. Such functions may in fact return a non-null pointer, but that must never be dereferenced.
realloc(ptr,0) is not equivalent to
free(ptr). It may
free(ptr), allocate a dummy element and return that
0for failure and do nothing else.
So in particular the latter two cases are indistinguishable by application code.
realloc(ptr,0) may not really free/deallocate the memory, and thus it should never be used as a replacement for