The parameters of the function call are known as actual parameters and the parameters of the function definition are known as formal parameters. There are 3 ways of passing parameters in a function and they are :-

- Call by Value
- Call by Address
- Call by Reference
1.Call by Value : In this Call by Value method, the value of the actual parameters is copied to the function’s formal parameters and different memory is allocated to the actual parameters and the function’s formal parameters. So, the changes made in the formal parameters will not be reflected in the actual parameters.
2.Call by Address: In this Call by Address method, the address of the actual parameters is passed to the function’s formal parameters and different memory is allocated to the actual parameters and the function’s formal parameters. So, the changes made in the formal parameters will also be reflected in the actual parameters.
3.Call by Reference: In this Call by Reference method, same memory address is used by both the actual parameters and the function’s formal parameters. So, the changes made in the formal parameters will also be reflected in the actual parameters.
| Call by Address | Call by Reference |
| It is also known as Call by pointer. The memory address of the actual parameters is passed to the formal parameter.
Memory is allocated for both the formal parameters and the actual parameters. Different memory address is used by the actual parameters and the formal parameters. C language does allow Call by Address. It is more advisable to use. |
In call by reference, the references of the actual arguments is passed to the formal parameters.
Memory is allocated to the actual parameters and formal parameters share that memory. Same memory address is used by both the actual parameters and the function’s formal parameters. C language doesn’t allow Call by reference. It is less advisable to use. |
// Call by Address
#include <iostream>
using namespace std;
// Here x and y are formal paramters and the pointers x and
// y will store the memory
// address of a and b and any change made in the formal
// parameters will also reflect in the actual parameters.
void swap(int* x, int* y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
return;
}
int main()
{
int a = 16, b = 32;
cout << "Before Swapping a and b are " << a << " " << b
<< endl;
// here a and b are actual parameters and we are passing
// the address of a and b
swap(&a, &b);
cout << "After Swapping a and b are " << a << " " << b
<< endl;
return 0;
}
// Call by Reference
#include <iostream>
using namespace std;
// Here x and y are formal paramters . x and a will share
// the
// memory address and y and b will share the memory address
// so any change made in the formal parameters x and y will
// also reflect in the actual parameters a and b.
void swap(int& x, int& y)
{
int temp;
temp = x;
x = y;
y = temp;
return;
}
int main()
{
int a = 16, b = 32;
cout << "Before Swapping a and b are " << a << " " << b
<< endl;
// here a and b are actual parameters and we are passing
// it by reference
swap(a, b);
cout << "After Swapping a and b are " << a << " " << b
<< endl;
return 0;
}