Brandon Lewis

Brandon Lewis

  • NA
  • 527
  • 125.4k

Reference or Value?

Jul 3 2007 11:31 AM

What is the difference between passing variables by reference or by value?

Im thinking that when you pass a variable by reference, you simply make a reference name for it in the parameters of the method that refers back to the variable that was "passed" to the method in the calling parameters. With this method you cannot actually change the contents of the passed variable.

With passing by value, you create a copy of the variable that is "re-instantiated" in the parameters of the method and can be modified and what not, just as if it were a variable that was declared in the method itself but it comes into the method with a preloaded value. Using this method, you CAN change the value of the passed variable.

How about it? Did I answer my own question? lol


Answers (2)