wood burning stoves 2.0*
The moose likes Java in General and the fly likes Difference between pass by reference and passing a copy of the reference by value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Difference between pass by reference and passing a copy of the reference by value" Watch "Difference between pass by reference and passing a copy of the reference by value" New topic
Author

Difference between pass by reference and passing a copy of the reference by value

Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
Hi Guys:
Can someone explain to me in lay mans term the difference between pass by reference as obtained in C and C++ and passing a copy of the reference by value as obtained in Java.
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
I believe you are saying the same thing. If I have a class A and pass it to method myMethod(A), it will be pased by reference. Here is what we might have -

myA holds a reference to the new A class. When myMethod is called, myA isn't passed into the method, a copy of the pointer myA points to is passed in. Thats why inside myMethod you can't change where myA is pointing, but you can call methods on the class myA points to.
HTH.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

The simple definition is:
C does not have "true" pass by reference.
Java does not have "true" pass by reference.
C++ does.
Passing pointers to objects in C is not pass by reference. It is passing by value the pointer to an object, just as Java works.
Pass by reference is a C++ construct that involves defining your method to take references as formal parameters, something that you cannot do in C.
As long as you think I am passing a reference to the object by value you should be fine.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
Thank McNarry; You cleared it up a bit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between pass by reference and passing a copy of the reference by value
 
Similar Threads
Help!!
return values in methods
Passing Objects to a Remote method
pass by reference
pass-by-reference and pass-by-value