[LCP]query
Vincent Penquerc'h
Vincent.Penquerch at artworks.co.uk
Fri Feb 1 21:22:44 UTC 2002
> > 12 char *p = "raman";
> > 13 printf("%s\n",p);
> > 14 strcpy(p, "shyam");
You're lucky not to get a SIGSEGV. Upon entry in abc, p gets
initialized with a pointer to somewhere in memory (which sometimes
is a read only segment) where is stored the litteral "raman".
The strcpy just overwrites this litteral, which may or may not
be legal depending on your env/compiler/OS. If you try to strcpy
a longer string, you might get into more trouble, as it may
overwrite other litterals/data stored after "raman".
K&R code usually take for granted that litterals can be written to.
Besides, you'll also run into surprises if your compiler decides
to merge litterals into a single memory area.
--
Vincent Penquerc'h
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.linux.org.au/pipermail/linuxcprogramming/attachments/20020201/debf8e17/attachment.htm
More information about the linuxCprogramming
mailing list