C++ Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
C++ Tutorial
C++ Language Tutorial - Object Oriented Programing - OOPs History of C++
C++ Language Tutorial - Object Oriented Programing - OOPs Structure of C++
C++ Language Tutorial - Object Oriented Programing - OOPs C++ Datatypes
C++ Language Tutorial - Object Oriented Programing - OOPs Variables
C++ Language Tutorial - Object Oriented Programing - OOPs Constants
C++ Language Tutorial - Object Oriented Programing - OOPs Operators
C++ Language Tutorial - Object Oriented Programing - OOPs Control Structures
C++ Language Tutorial - Object Oriented Programing - OOPs Arrays
C++ Language Tutorial - Object Oriented Programing - OOPs Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Class
C++ Language Tutorial - Object Oriented Programing - OOPs Predefined Functions
C++ Language Tutorial - Object Oriented Programing - OOPs I/O Functions
C++ Language Tutorial - Object Oriented Programing - OOPs String, Character Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Mathematical Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Time Date Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Dynamic Allocation
C++ Language Tutorial - Object Oriented Programing - OOPs Utility Functions
C++ Language Tutorial - Object Oriented Programing - OOPs OOP's Concept
C++ Language Tutorial - Object Oriented Programing - OOPs Special Topics
C++ Language Tutorial - Object Oriented Programing - OOPs Type casting
C++ Language Tutorial - Object Oriented Programing - OOPs Feedback
C++ Language Tutorial - Object Oriented Programing - OOPs Ask Your Doubts
 





Pass By Reference - Function


Tutorials Cpp

Topic

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



Explanation

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';
   	changes(x,y);
   	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++.








Note
C++ is one of the most used programming languages in the world. Also known as "C with Classes". Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.

Other Links

web hosting