+ 1

Why B =2 in answer?

void f(int &x){ cout<<x++; x=2; } int main(){ int a=3; int &b=a; f(a); cout<<" b"<<b; }

4th Aug 2017, 9:41 AM
Vladyslav Sabadakh
Vladyslav Sabadakh - avatar
3 Antworten
+ 10
When you do int &b = a; b is simply an alias for a. (i.e. b is a). a gets passed into f() via reference, and the value is altered to 2.
4th Aug 2017, 9:52 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
because it is passed by reference so its value can be modified by the function f
4th Aug 2017, 9:41 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
- 1
watch my sudoku solver in python))
4th Aug 2017, 9:54 AM
Vladyslav Sabadakh
Vladyslav Sabadakh - avatar