I use DevC++ as my compiler.
I used the following two codes:
and the second code asCode:#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char *p,c; 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 ?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(); }



LinkBack URL
About LinkBacks


