Re: Reset a string?
From: Adrian de los Santos (demonNOSPAM_at_demon.com.mx)
Date: 03/06/04
- Next message: Adrian de los Santos: "Re: header files"
- Previous message: benjamin disraeli: "Re: HOW MANY PEOPLE HAVE CHRISTIANS KILLED SINCE BIBLICAL TIMES?"
- In reply to: Tor Husabø: "Re: Reset a string?"
- Next in thread: Chris Torek: "string literals (was Reset a string?)"
- Reply: Chris Torek: "string literals (was Reset a string?)"
- Reply: Barry Schwarz: "Re: Reset a string?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 6 Mar 2004 14:00:34 -0600
On 2004-03-06 13:22:24 -0600, Tor Husabø <torhu@student.hf.uio.no> said:
> char *str does not become a constant! It's "hello" that is "constant"
> (in the sense that modifying it is has undefined behavior, even
> if it might work on your implementation).
>
> This is allowed, however:
>
> char other_string[] = "goodbye";
> char *str="hello";
> str = other_string;
>
> now str points to "goodbye", and "hello" is just wasted memory, since
> you dont have the address anymore.
Oh yea i read the faq, thanks a lot for pointing me there..
So, as the faq says
- A string literal can be:
- An array initializer
- An unamed static array of chars
So my question its:
if i declare:
char *myString="Whatever";
and later in the code:
myString="Another Static Array of chars";
the pointer value will be the same ?
i mean:
"Another Static Array of chars" will start on the same memory address
than "Whatever" ?
Another questions
If i:
char *MyString1="Dog";
char *MyString2="Cat";
MyString1=Mystring2;
What happens with the initial memory referenced by MyString1 (Dog), it
remains on the memory (wasted memory) or it gets cleared in some way ?
Thanks for your helpful answers, im learning.
- Next message: Adrian de los Santos: "Re: header files"
- Previous message: benjamin disraeli: "Re: HOW MANY PEOPLE HAVE CHRISTIANS KILLED SINCE BIBLICAL TIMES?"
- In reply to: Tor Husabø: "Re: Reset a string?"
- Next in thread: Chris Torek: "string literals (was Reset a string?)"
- Reply: Chris Torek: "string literals (was Reset a string?)"
- Reply: Barry Schwarz: "Re: Reset a string?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|