call by reference in c++

/*In call by reference we pass (&)address as argument or parameter in definition of function and while calling the function we pass only variables of the original value.
  */

#include<iostream>
using namespace std;
void swap(int &,int &);
int main(){
int a,b;
cout<<“Enter A and B “<<endl;
cin>>a>>b;
cout<<“Before swapping “;
cout<<” A “<<a<<” B “<<b;
swap(a,b);
cout<<” After swapping “;
cout<<” A “<<a<<” B “<<b;
}
void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
output-
Enter A and B
9
5
Before swapping  A 9 B 5 After swapping  A 5 B 9

Leave a Comment

Your email address will not be published. Required fields are marked *

To Resolve this issue at just 5$ from ServerExpert

https://serverexpert.io/

For Hosting please visit Hostingwebsite.io

You have Successfully Subscribed!

Open chat