0
When and how can I use the (&) operator in functions .
in c++ please
5 Answers
+ 6
The simplest example:
void swap(int& a,int& b)
{
int t = a;
a = b;
b = t;
}
int main()
{
int a, b;
cin>>a>>b; swap(a,b);
cout<<a<<" "<<b;
}
+ 1
& denoted the position in memory,If you just use the variable name the value will be passed and you get only the value you need,But if you use & operator you get the address of the position and you can do two things,access value or access the position to make changes to the variable.
0
c++