Passing values to and from a function: Difference between revisions
From MultiCharts
Passing values to and from a function (view source)
Revision as of 11:10, 27 January 2012
, 27 January 2012no edit summary
(Created page with "This article highlights the differences between ''passing by value'' and ''passing by reference'', and gives examples of how this is used in Functions. == Passing variabl...") |
No edit summary |
||
Line 11: | Line 11: | ||
This is a somewhat abstract concept, but let’s assume I’ve got a handwritten piece of paper and a friend wants to borrow it. If I make a copy of this piece of paper, and give the copy to my friend, I’m ''passing by value'' and anything that he writes on the paper will not affect my original version (since I gave him a copy). However, if I give the original version to my friend, I’m passing by reference, and any changes he make will change my original paper. | This is a somewhat abstract concept, but let’s assume I’ve got a handwritten piece of paper and a friend wants to borrow it. If I make a copy of this piece of paper, and give the copy to my friend, I’m ''passing by value'' and anything that he writes on the paper will not affect my original version (since I gave him a copy). However, if I give the original version to my friend, I’m passing by reference, and any changes he make will change my original paper. | ||
== To summarize == | |||
* If a variable is ''passed by value'', a copy of the variable is send leaving the original variable value intact. | * If a variable is ''passed by value'', a copy of the variable is send leaving the original variable value intact. |