scanning and printing a string
I use DevC++ as my compiler.
I used the following two codes:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char *p,c;
gets(p);
printf("%s", p);
getch();
}
and the second code as
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char *p,c;
p = (char *)malloc(0);
gets(p);
printf("%s", p);
getch();
}
the first code runs into a segmentation fault while the second one runs perfectly fine. What is the reason ? isnt doing malloc(0) same as not using the malloc() statement ?