Possible Duplicates:
What's the difference between passing by reference vs. passing by value?
Java and C++ pass by value and pass by reference
Java is "pass by value" or "pass by reference"?
and what about c++ and c?
is c++ and c "passed by value" or "passed by reference"?
and what is the difference between "pass by value" or "pass by reference"?
Answer
Java is pass by value, but the value you pass may be a reference.
In C++, you choose whether to pass by value or by reference. In C, you always pass by value, and there is no such thing as a reference; you have to pass a pointer to do something similar.
If you pass by value, the function gets a copy of the variable you pass. If you change the copy, the original value remains the same (though, it the value passed was itself a reference, you may change the referred object).
If you pass by reference, the function gets the actual variable passed. If the function changes that variable, you are actually changing the variable that was passed to the function.
No comments:
Post a Comment