[LCP]query

Santosh.Kawade at eyield.com Santosh.Kawade at eyield.com
Fri Feb 1 19:47:58 UTC 2002


>       I have a query in C which has baffled me for sometime...
>       Please consider the following C programme -
>
>      1  #include <stdio.h>
>      2
>      3  void abc();
>      4  main()
>      5  {
>      6    abc();
>      7    abc();
>      8  }
>      9
>     10  void abc()
>     11  {
>     12     char *p = "raman";
>     13     printf("%s\n",p);
>     14     strcpy(p, "shyam");
>     15  }
>
>      The O/P of the program is -
>       raman
>       shyam
>
>     Though one would expect that the word 'raman' will be printed twice.
>     I think that the O/P obtained is related to the fact that string
>     literals are stored in data segment.




More information about the linuxCprogramming mailing list