Sunday, April 19, 2015

OOP using c++

Pass by Reference Function Example

#include<iostream>//for cin and cout objects
using namespace std;//definition of cin and cout object lies in std namespace
void swap(int &a,int&b)//function prototype

//use address operator (this operator return the memory address of variable)
{
int temp;
temp=a;
a=b;
b=temp;
}
void main()
{
int x=2;
int y=4;
swap(x,y);
cout << x << endl ;
cout << y << endl ;
        system("pause");
}