Re: Reset a string?

From: Adrian de los Santos (demonNOSPAM_at_demon.com.mx)
Date: 03/06/04


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.



Relevant Pages

  • Re: image graphics drawing confusion
    ... suggest you subscribe to the RSS feed for the FAQ. ... since the thumbnail ... > System.IO.MemoryStream to create an image from a file buffer in memory. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Im stumped!!
    ... > is the problem In the main loop that creates the vertex and index buffers, ... > write to some memory that I shouldn't have, but If I'm wrong, please ... > allows the program to run without access violations. ... a.c.l.l.c-c++ FAQ mirror: http://nullptr.merseine.nu:8080/acllcc++.html ...
    (alt.comp.lang.learn.c-cpp)
  • Re: FileSize() function
    ... When counting characters, the O.S. may translate ... into memory, the safe technique is to allocate some N ... C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: ... Other sites: http://www.josuttis.com -- C++ STL Library book http://www.sgi.com/tech/stl -- Standard Template Library ...
    (comp.lang.cpp)
  • Re: Mystery: static variables & performance
    ... > use of a static array within a performance-critical transform function. ... operation, variable, or memory usage over another. ... underlying hardware, and the ...
    (comp.lang.c)
  • Re: i get a command execution error whilst trying to open up a mpp
    ... Memory problems aren't necessarily RAM but could be lack of virtual memory. ... Please see FAQ Item: 18. ... David Hunsberger ... you might have a corrupt file. ...
    (microsoft.public.project)