Reference Parameter In C++
Whenever
we pass a function of any kind to inside so we can use parameter so that time
we have to use address operator so it’s known as reference parameter.
When
the actually argument through the variable to pass a value, so that time if we
use to define the address operator, so it called reference parameter.
Fig: Reference Parameter In C++
Syntax:
return
type functionname(datatype &variable)
{
function
of body;
}
Program:
#include<iostream.h>
#include<conio.h>
void
swap(int &i, int &j);
void
main()
{
int
a,b;
cout<<”input
two no”;
cin>>a>>b;
swap(a,b);
cout<<”a=”<<a;
cout<<”b=”<<b;
getch();
}
void
swap(int &i, int &j)
{
int
k;
k=i;
j=i;
i=k;
}
Output:
Input
two no 12
12
a=12,
b=12
No comments:
Post a Comment