On Wed, Jun 18, 2008 at 6:54 PM, vaibhav khatavkar <khatavkarvaibhav86@xxxxxxxxx> wrote:
But why the complier is unable to resolve it when p is null? and it works when add a space after it?
Hi Wang Yu ,
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 ..
But why the complier is unable to resolve it when p is null? and it works when add a space after it?
I don't know why....
Thanks!
--
National Research Center for Intelligent Computing Systems
Institute of Computing Technology, Chinese Academy of Sciences
--
with regards,
vaibhav
--
National Research Center for Intelligent Computing Systems
Institute of Computing Technology, Chinese Academy of Sciences