01-28-2008, 09:20 PM
|
#9 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Posts: 166
Thanks: 0
|
Quote:
Originally Posted by xenon
References will not create a copy of the variable being sent, but instead use the memory handle of that variable to manipulate it. I don't know if there is actually more to know about them, but the fact that a reference to a variable points to the same variable, where as a copy points to another, different, variable (changing the reference affects the original variable, changing the copy does not).
|
To expand on this, variables are only available within their scope. Scope being within a function, loop, whatever. So when you have a variable you are passing into a function through a parameter, it creates a copy of that variable in memory for use within the function because the function is not within the scope of the variable. So you can do whatever you want with the variable you passed in through a parameter and not have it change the variable outside of the function. When you pass the variable in by reference, it doesn't create the copy and extends the scope of the variable to include the function so changing it within the function changes outside of the function as well.
__________________
Eric
|
|
|
|