Re: A interesting problem of C programming

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <stdio.h>                                                                                                                                                                  &nb sp;                                                              
int main()                                                                                                                                
{                                                                                                                                         
                                                                                                                                          
    char *p;                                                                                                                              
    p = 0;                                                                                                                                
    printf("%s", p);                                                                                                                      
    printf("\n");   
                                                                                                                      
    return 0;                                                                                                                             
}

The out put is (null)
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 !

I don't know why....
Thanks!
--
National Research Center for Intelligent Computing Systems
Institute of Computing Technology, Chinese Academy of Sciences

-- 

Regards,
R.S.Shree Ram
GDA Technologies Ltd.

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux