Re: strings
From: .:'DevarajA':. (no_at_spam.com)
Date: 08/22/04
- Next message: Alwyn: "Re: Data hiding in C++"
- Previous message: Chris \( Val \): "Re: Data hiding in C++"
- In reply to: James Dennett: "Re: strings"
- Next in thread: Alwyn: "Re: strings"
- Reply: Alwyn: "Re: strings"
- Reply: Barry Schwarz: "Re: strings"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 22 Aug 2004 09:45:12 GMT
"James Dennett" <jdennett@acm.org> wrote:
> .:'DevarajA':. wrote:
>
> > char *msg = "a string"; is there something wrong with this?
>
> Yes; it is not "const correct", in that you have set a
> char* to point at a const char.
>
> If after the declaration above you executed
>
> *msg = 'b';
>
> then you would have "undefined behavior"
>
sorry, maybe i've not understood...
If I executed it..., but I just need to have a string which can be read when
needed. The program doesn't modify it. In this case would it be correct?
I've also been told that char *msg = "aaa" writes the string aaa in a
random memory location, sometimes overwriting important data. Is it true?
- Next message: Alwyn: "Re: Data hiding in C++"
- Previous message: Chris \( Val \): "Re: Data hiding in C++"
- In reply to: James Dennett: "Re: strings"
- Next in thread: Alwyn: "Re: strings"
- Reply: Alwyn: "Re: strings"
- Reply: Barry Schwarz: "Re: strings"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|