Pointers and references: Difference between revisions

No edit summary
Line 328:
}
 
Java is call-by-value. withWhen primitivespassing andarguments, you are either passing primitives call-by-reference withvalue objects.or Soreferences itby isvalue. notThere possibleis tono changesuch thething valueas of"passing aan primitiveobject" variableas ofobjects theare callernot thatvalues isin passedthe inlanguage. As noted above, if the object that the reference is pointing to is mutable, then it is possible to modify that object's state through the reference, or change the reference altogether. Then if the calling function has a reference to the same object, they will see that modification through the reference. So if you want to reflect changes in an argument back to the caller, one thing that you can do is wrap the argument as a field in an object, then modify the object through the reference.
 
=={{header|OCaml}}==
Anonymous user