Saturday 28 December 2013

C++ Program For Swap Value Using Call By Value

#include<iostream.h>
swap(int,int);
void main()
{
int x=10, y=20;
cout<<“Before calling swap:”<<x<<y;
swap(x,y);
cout<<“After calling swap :”<<x<<y;
}
swap(int a, int b)
{
int temp;
temp=a;
a=b;
b=temp;
cout<<“with swap function”<<a<<b;
}

/*

Output
Before calling swap : x=10, y=20
With swap function : a=20, b=10
After calling swap : x=10, y=20

*/

No comments:

Post a Comment