"pradeep singh" <pr*************@gmail.com> writes:
questions? wrote: What's wrong with the following sudo-code? correction its not pseudo code :)
char *test="I am the string you testing on";
[...] It is pretty simple why you are getting a seg fault. All strings are by
default const char * .This means if try changing it you will be
sefgaulted. I hope you understand this :)
No string literals are not const char*. A string literal is of type
char[N], where N is the number of characters required (the length plus
one for the trailing '\0'). Like any expression of array type, it's
converted to a pointer value in most contexts, in this case a pointer
value of type char* (no const).
Attempting to modify a string literal invokes undefined behavior
because the standard says so, not because it's const.
(Making string literals const might have been better in some ways,
<OT>and C++ does so</OT>, but it would also have broken existing
code.)
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.