Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Call by Reference in User-defined Functions of Programming in CPP
1203 Views
Usage 
The call by reference method can be used to pass arguments/values to the functions as reference of arguments.
Example
#include <iostream>
using namespace std;

void change(int &x, int &y);

int main ()
{

   int u = 5;
   int v = 3;
   cout<<"Before swap";
   cout << "value of u :" << u << endl;
   cout << "value of v :" << v << endl;

   change(u, v);
cout<<"After swap";
   cout << "value of U :" << u << endl;
   cout << "value of V :" << v << endl;

   return 0;
}

void change(int &x, int &y)
{
   int temp;
   temp = x;
   x = y;   
   y = temp;
 
   return;
}
Output 
Before swap
value of u :5
value of v:3
 
After swap
value of U :3
value of V :5
Next Topics
Next lessons of current book.
User-defined Functions of Programming in CPP
Previous Topics
Previous lessons of current book.
User-defined Functions of Programming in CPP
User-defined Functions of Programming in CPP
String Class in CPP of Programming in CPP
String Class in CPP of Programming in CPP
String Class in CPP of Programming in CPP
Best Lessons of "Programming in CPP"
Top lessons which are viewed more times.
String Class in CPP of Programming in CPP
Math Library Functions of Programming in CPP
String Class in CPP of Programming in CPP
Math Library Functions of Programming in CPP
User-defined Functions of Programming in CPP
Math Library Functions of Programming in CPP
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details