Pass by Reference in Functions

Learn a method to pass the reference of the actual parameters to the function.

Introduction

Suppose you have sent an email to your friend with a link to a file present on Google Drive. Your friend made some changes to the document. Since you and your friend are sharing the same file, you will both see the changes made by either of you in the document.


In pass by reference, when we call a function, we pass the address of the actual parameters to the formal parameters in the function.


In pass by reference, the actual and formal parameters refer to the same memory location. Any changes made in the formal parameters inside the function affect the values of actual parameters in the main function.

Basic syntax

The general syntax for passing a reference to the function parameters is given below:

Get hands-on with 1400+ tech skills courses.