Can someone explain the segmentation fault
#include<stdio.h>
#include<string.h>
int main()
{
        char *s1="hello1";
        char *s2="hello2";
        {
        strcpy(s1, s2);
        printf("%s\n", s1);
        }
        }

[EMAIL PROTECTED] ~/CSSp08]$ ./a.out
Segmentation fault (core dumped)-  can occur during the operation of computer 
software. A segmentation fault occurs when a program attempts to access a 
memory location that it is not allowed to access
bob

--- On Thu, 7/24/08, Paul Herring <[EMAIL PROTECTED]> wrote:
From: Paul Herring <[EMAIL PROTECTED]>
Subject: Re: [c-prog] strcpy() crashed
To: [email protected]
Date: Thursday, July 24, 2008, 6:47 AM










    
            On Thu, Jul 24, 2008 at 12:05 PM, kathir resh <resh_personal@ 
yahoo.co. in> wrote:

> char *s1="hello";

>  char *s2="hai"

>  strcpy(s1,s2) ;

>  printf("%s", s1);

>

>  i am getting the correct output..in previous msg why they said its 
> crashing...



'undefined behaviour' also includes 'appearing to work correctly.'



>  and say in detail about wh difference between char *s1="hello" and char s[ 
> ]="hello";



One is modifiable, the other isn't: http://c-faq. com/decl/ strlitinit. html



-- 

PJH



'Two Dead in Baghdad' not 'product-friendly' - Kent Ertugrul, chief

executive of Phorm.



http://shabbleland. myminicity. com


      

    
    
        
         
        
        








        


        
        


      

Reply via email to