Tuesday, 3 February 2015

Function call by reference in C++

Structure of the Problem Requirements

There are two types of function calling , call by values and call by reference. In function call by reference we declare the function parameters by reference instead of normal variables. Inside the function ,the reference is used to access the actual parameters used in call.In this example we swap the two integers with call by reference function.

Source Code

using namespace std;
void swap (int &a , int &b);
int main ()
int num1,num2;
char c;
cout<<"\t \t \t LEP Tutorials \n ";
cout<<" Enter Your 1st Number : ";
cout<<" Enter Your 2nd Number : ";
cout<<"\t Do You Want to Swap these Values ? Y/N ";
if ( c =='y' || c== 'Y')
swap (num1,num2);
cout<<" After Swap 1st Number :"<<num1;
cout<<" After Swap 2nd Number :"<<num2;
return 0;
void swap (int &a, int &b)
int temp ;
temp = a;
a = b;
b = temp;

Output of the Program

Function call by reference in C++

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.


Post a Comment