Monday, March 26, 2012

Program using call by value and call by refrence in c++

/**************<soeasyprograms.blogspot.in>*****************/
#include<iostream.h>
#include<conio.h>
void swap(int x,int y)
{
int z;
z=x;
x=y;
y=z;
cout<<"After modification of values\n";
cout<<"x is "<<x<<"\ny is "<<y<<endl;
}
void swap1(int &x,int &y)
{
int z;
z=x;
x=y;
y=z;
cout<<"After modification of values\n";
cout<<"x is "<<x<<"\ny is "<<y<<endl;
}
main()
{
int a,b;
clrscr();
cout<<"enter the value of a & b";
cin>>a>>b;
swap(a,b);
cout<<"By using value\n";
cout<<"a is "<<a<<endl<<"b is "<<b<<endl;
cout<<"By using refrence\n";
swap1(a,b);
cout<<"a is "<<a<<endl<<"b is "<<b;
getch();
}
/**************<soeasyprograms.blogspot.in>*****************/

No comments:

Post a Comment