Thursday, October 16, 2014

call by reference



Prog 12 : Write a Program to swap two values using call by reference


#include<iostream.h>
#include<conio.h>
#include&ltiomainp.h>
void swap(int *,int *);
void swap(int *a,int *b)
{
int c;
c=*a;
*a=*b;
*b=c;
}
void main()
{
clrscr();
int a,b;
cout<<"\n Enter value of a";
cin >>a;
cout<<"\n Enter value of b";
cin >>b;
cout<<"\n before swapping a and b are";
cout<<"\n a="<<a"b="<<b;
cout<<"\n After swapping a and b are";
cout<<"\n a="<<a"b="<<b;
}



Output:

Enter value of a 10

Enter value of b 20

before swapping a and b are a=10
b=20
After swapping a and b are a=20
b=10

No comments: