I've written the following code :
#include <stdio.h>
#include <stdlib.h>
int main()
{
char* ch = malloc(0 * sizeof(char));
int n = 300;
sprintf(ch, "%d", n);
printf("ch is : %s", ch);
return 0;
}
I've switched the 0 in the malloc function to different numbers to experiment and I tried putting 0 meaning allocating no memory but when I run the program it worked just fine and I don't understand why is that exactly because if I put 0 it's like allocating no memory at all so what's happening here ?