Computer Science, asked by abhinav222, 1 year ago

demonstrate the swapping of two numbers by using functions where parameter are Call by Value and Call by Reference

Answers

Answered by sandew
2
//swapping a number using call by reference.
#include<iostream.h>
void swap(int &, int &);
void main()
{
int a, b;
cin>>a>>b;
cout<<"Before swapping :"<<"\n a="<<a<<"\n b="<<b;
swap(&a,&b);
getch();
}
void swap(int &a, int, &b)
{
int temp;
c=a;
a=b;
b=c;
Cout<<"After swapping :"<<"\n a="<<a<<"\n b="<<b;
}
For call by value u just remove the symbol of this '&' then u vll get ur program in call by value..
so I hope this answer may help to solve ur doubts u had....
Similar questions