On 9/17/07, Nicholas Blatter <[EMAIL PROTECTED]> wrote:
> My understanding is that since temp is allocated with new[], the
> memory that temp points to is on the heap.  Because of this, when you
> modify array to point at that heap location, even though the function
> returned and the stack invalidated, the temp pointer along with is,
> array still points to the heap and that memory is still valid.

The memory that temp points to is indeed on the heap.  However, the
value of array is passed by value, so it will be the same value when
it returns.  If it were passed by reference, as preceding the
parameter with an & would do, the new value would be returned.  What
this means is that within the function, you delete what array points
to, then tell array to point to temp.  When the function returns,
array is not changed due to pass-by-value, so it points back to where
it did before the function, which is memory that you have now deleted.
 The memory you allocated in the function is still there, but noone is
pointing to it.

Derek
--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info: http://uug.byu.edu/mailman/listinfo/uug-list

Reply via email to