0

When and how can I use the (&) operator in functions .

in c++ please

9th Dec 2017, 4:57 AM
Hameido
Hameido - avatar
3 odpowiedzi
+ 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; }
9th Dec 2017, 5:03 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 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.
9th Dec 2017, 7:02 AM
Joel Roy
Joel Roy - avatar
0
c++
9th Dec 2017, 4:59 AM
Hameido
Hameido - avatar