I saw ur code ...
In ur first code snippet "%s" prints string located at p .. and thats null .. so we get output null ... (Note that : there are 2 printf statements)
char *p;
p = 0;
printf("%s", p);
printf("\n");
The out put is (null)
Now when u changed it like this ...
But, if I change into:
#include <stdio.h>
int main()
{
char *p;
p = 0;
printf("%s\n", p);
return 0;
}
The output will be Segment fault!
The segmentation fault comes just because in printf statement u have written "%s\n" .. compiler is unable to resolve it ... when u add a space between %s and \n the output is null and not segmentation fault ..
I don't know why....
Thanks!
--
National Research Center for Intelligent Computing Systems
Institute of Computing Technology, Chinese Academy of Sciences
--
with regards,
vaibhav