Re: Why this code is working



jammie_linux@xxxxxxxxx writes:
> But when a function returns, the compiler reclaims all the memory
> assigend to the local variables. By this theory, isn't it possible that
> the memory where the string "This is local to the function" was
> stored, would also be reclaimed. In that case, the main's function str
> will be pointing at a totally meaningless position.

Don't assume your readers can see the article to which you're
replying. You need to provide some context in the form of properly
attributed quotations from the parent article (not necessarily the
whole thing, just what's relevant to your reply). See nearly any
followup in this newsgroup for an example.

Google Groups makes this gratutiously difficult. Please follow these
instructions (which have been posted here over 1000 times), and
*please* complain to Google about their broken interface, which
they've persistently refused to fix.

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <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.
.



Relevant Pages

  • Re: when to use "new"
    ... Maybe you should understand what the stack is and what the heap is. ... the memory for local variables are ...
    (comp.lang.cpp)
  • Re: Problems with Scope of aliased Objects
    ... memory space on the stack, which it uses for local variables. ... "new" to allocate heap-memory dynamically. ...
    (comp.lang.ada)
  • Re: Deallocating Local Variable used by Malloc
    ... A conforming C compiler may not compile the above line. ... char *ret_buf; ... Also dynamically allocated memory persists even after execution ... Also returning local variables may cause ...
    (comp.lang.c)
  • Re: Local variables in Java
    ... only one copy of all local variables defined (while method calls are ... Threads tend to be "synchronized by default" in a uniprocessor environment. ... The rules for this are called Java's "memory model". ... Without synchronization, the system might not share memory changes across CPUs. ...
    (comp.lang.java.programmer)