Why allocating a 0 size char block works in this case? But if I write char *string = NULL; it won\'t work.
char
char *string = NULL;
I\'m using Visual Studio.
The above code invokes undefined behavior. You have allocated insufficient memory and you are accessing invalid addresses.
According to the specifications, malloc(0) will return either "a null pointer or a unique pointer that can be successfully passed to free()".