char *p = NULL;
printf("%s", p);
Why does above does not lead segmentation fault? But
char *p = NULL;
printf("%s\n",p);
does?
To add i know it is undefined behavior to use in this way but still wondering why does it generates segmentation fault 6 out of 6 times with \n while not without it.
I was asked this question in interview and i gave same answer as its undefined behavior but their expectation was to give reason for it and i do not know what else can i add. Any thoughts on it?