Pass by Reference
This lesson introduces the ways by which we pass values to a function by reference.
We'll cover the following...
What is Pass by Reference? #
When passing arguments by pass by reference, the original value is passed. Therefore, the original value gets altered. In pass by reference, we actually pass the value using ampersand sign &
. The additional &
is very important: it tells the compiler that the data is a reference to the value rather than simply the value itself.
Example: Swap Numbers #
Now let’s redefine the interchange
function from the example in the previous lesson.