<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2448.0">
<TITLE>RE: [LCP]query</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>> > 12 char *p = "raman";</FONT>
<BR><FONT SIZE=2>> > 13 printf("%s\n",p);</FONT>
<BR><FONT SIZE=2>> > 14 strcpy(p, "shyam");</FONT>
</P>
<P><FONT SIZE=2>You're lucky not to get a SIGSEGV. Upon entry in abc, p gets</FONT>
<BR><FONT SIZE=2>initialized with a pointer to somewhere in memory (which sometimes</FONT>
<BR><FONT SIZE=2>is a read only segment) where is stored the litteral "raman".</FONT>
<BR><FONT SIZE=2>The strcpy just overwrites this litteral, which may or may not</FONT>
<BR><FONT SIZE=2>be legal depending on your env/compiler/OS. If you try to strcpy</FONT>
<BR><FONT SIZE=2>a longer string, you might get into more trouble, as it may</FONT>
<BR><FONT SIZE=2>overwrite other litterals/data stored after "raman".</FONT>
<BR><FONT SIZE=2>K&R code usually take for granted that litterals can be written to.</FONT>
<BR><FONT SIZE=2>Besides, you'll also run into surprises if your compiler decides</FONT>
<BR><FONT SIZE=2>to merge litterals into a single memory area.</FONT>
</P>
<P><FONT SIZE=2>-- </FONT>
<BR><FONT SIZE=2>Vincent Penquerc'h </FONT>
</P>
</BODY>
</HTML>