Pass by Reference

This lesson introduces the ways by which we pass values to a function by reference.

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.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy