Before we discuss function call by reference, lets understand the terminologies that we will use while explaining this:
Actual parameters: The parameters that appear in function calls.
Formal parameters: The parameters that appear in function declarations.
For example: We have a function declaration like this:
int sum(int a, int b);
The a and b parameters are formal parameters.
We are calling the function like this:
int s = sum(10, 20); //Here 10 and 20 are actual parameters or int s = sum(n1, n2); //Here n1 and n2 are actual parameters
In this post, we will discuss function call by reference method. If you want to read call by value method then refer this post: function call by value.
What is Function Call By Reference?
When we call a function by passing the addresses of actual parameters then this way of calling the function is known as call by reference. In call by reference, the operation performed on formal parameters, affects the value of actual parameters because all the operations performed on the value stored in the address of actual parameters. It may sound confusing first but the following example would clear your doubts.
For any query or issue, feel free to discuss on http://discuss.eduguru.in