Re: A interesting problem of C programming

2008-06-18 Thread Jose Celestino
Words by vaibhav khatavkar [Wed, Jun 18, 2008 at 04:24:31PM +0530]: > Hi Wang Yu , > > I saw ur code ... > > > > > > > > char > > *p; > > > > p = > > 0; > > > > *printf("%s", > > p); > > > > printf("\n"); * > > > > > In ur first code snippet "%s" prints string loc

Re: A interesting problem of C programming

2008-06-18 Thread shreeram
Hi Trying to dereference a NULL pointer gives you a segmentation fault. Do not try to do this in kernel space. Doing so will lead to kernel panic. Wang Yu wrote: Hi, all I have the following code: #include

Re: A interesting problem of C programming

2008-06-18 Thread vaibhav khatavkar
Hi , On Wed, Jun 18, 2008 at 4:44 PM, Wang Yu <[EMAIL PROTECTED]> wrote: > > > On Wed, Jun 18, 2008 at 6:54 PM, vaibhav khatavkar < > [EMAIL PROTECTED]> wrote: > >> Hi Wang Yu , >> >> I saw ur code ... >> >> >>> >>> >>> char >>> *p; >>> >>> p = >>> 0; >>> >>> *printf("%s",

Re: A interesting problem of C programming

2008-06-18 Thread Wang Yu
On Wed, Jun 18, 2008 at 6:54 PM, vaibhav khatavkar < [EMAIL PROTECTED]> wrote: > Hi Wang Yu , > > I saw ur code ... > > >> >> >> char >> *p; >> >> p = >> 0; >> >> *printf("%s", >> p); >> >> printf("\n"); * >> >> > In ur first code snippet "%s" prints string located

Re: A interesting problem of C programming

2008-06-18 Thread shreeram
Hi Try to leave a space between the format and newline tab and get the ouput. Wang Yu wrote: Hi, all I have the following code: #include

Re: A interesting problem of C programming

2008-06-18 Thread ershaad ahamed
A quick google got me this http://www.ciselant.de/projects/gcc_printf/gcc_printf.html seems its a feature of gcc. In certain circumstances it optimizes the printf call to a puts call. While printf behaves nicely and prints '(null)' when you pass it a null pointer, puts doesnt do that. From the doc

Re: A interesting problem of C programming

2008-06-18 Thread Luciano Rocha
On Wed, Jun 18, 2008 at 05:52:20PM +0800, Wang Yu wrote: > Hi, all > I have the following code: > char *p = 0; > printf("%s", p); Using a NULL pointer with %s format isn't portable nor defined. Don't do that... -- Luciano Rocha <[EMAIL PROTECTED]> Eurotux Informática, S.A.

Re: A interesting problem of C programming

2008-06-18 Thread Bernd Petrovitsch
On Mit, 2008-06-18 at 16:14 +0530, ershaad ahamed wrote: > A quick google got me this > http://www.ciselant.de/projects/gcc_printf/gcc_printf.html > > seems its a feature of gcc. In certain circumstances it optimizes the > printf call to a puts call. While printf behaves nicely and prints s/print

Re: A interesting problem of C programming

2008-06-18 Thread vaibhav khatavkar
Hi Wang Yu , I saw ur code ... > > > char > *p; > > p = > 0; > > *printf("%s", > p); > > printf("\n"); * > > 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) > > T

Re: A interesting problem of C programming

2008-06-18 Thread ajit mote
Hello all, i tried the given code snippet and found 'null' output both the time ... compiled and run using gcc (GCC) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4) ... Regards, Ajit Mote. On Wed, Jun 18, 2008 at 3:22 PM, Wang Yu <[EMAIL PROTECTED]> wrote: > Hi, all > I have the following code

A interesting problem of C programming

2008-06-18 Thread Wang Yu
Hi, all I have the following code: #include int main() { char *p; p = 0; *printf("%s", p); printf("\n"); * return 0; } The out put is *(null)* But, if I change into: #include int main() { char *p; p = 0; * printf("%s\n", p); * return