Pass by Reference vs Pass by Value

The terms Pass by Reference and Pass by Value are two object passing strategies1 used to explain what a programming language do when objects are passed to methods.

The former treats the passed objects as “references” to the original object, while the later treats them as “values” (new copies of the original).

See also: Variables as Pointers

Pass by Reference

When you “pass by reference”, the method has a reference, in other word a pointer to the location of the passed object. In that case, modifying the object inside the method actually modify the original, referenced object.

Pass by Value

When you “pass by value”, the method only has a copy of the original object. In other word, the original object is not affected by what happens to the object within the method.

  1. Object passing strategies are strict evaluation strategies. Another evalution strategy is lazy evaluation.

    ↩︎