What if NULL and size 0 are passed to realloc()?
问题 Is the behavior implementation defined? If NULL and size == 0 are passed to realloc() : int main(void) { int *ptr = NULL; ptr = realloc(ptr, 0); if(ptr == NULL) { printf("realloc fails.\n"); goto Exit; } printf("Happy Scenario.\n"); Exit: printf("Inside goto.\n"); return 0; } The above code should print "realloc fails", right? But it is not? I've read somewhere that this call to realloc may return NULL also. When does that happen? 回答1: This behavior is implementation defined. From the C