Pass By Reference - Function

What is Function Calls?
How to pass by reference in C++?


Pass by reference or Call by reference is the method by which the address of the variables are passed to the function. The "&" symbol is used to refer the address of the variables to the function.

Example :

#include <iostream.h>
void main( )
void changes( int& , int& );
int x =10, y=20;
cout << "Value of X is::" << x << '\n';
cout << "Value of Y is::" << y << '\n';
cout << "Changed value of X is::" << x << '\n';
cout << "Changed value of Y is::" << y << '\n';
void changes(int& a, int& b)
a = a* 10;
b = b*100;

Result :

Value of X is::10
Value of Y is::20
Changed value of X is::100
Chnaged value of Y is::2000

In the above example the product of the numbers are calculated by passing the address of "x,y" to the variables "a,b" to the function "changes". This is the function calls in C++.

C++ Tutorial

Ask Questions

Ask Question