Reference passing allows variable to be modified by the function it's passed to.
Primitive types (int, double etc...) and Strings are passed by value.
Let's look at the following example:
Output:
num
is incremented by 1 in theincrementValue
function. Since it's passed
by value it remains 0
in the main
function.
Arrays and objects are always passed by reference.
Output: