0
Anyone can explain me what means void f(int& r) and why the output of this code is 1?
why the output of the code following code is 1? #include <iostream> using namespace std; void f(int& r){ } int main() { int i = 3; f(i); cout << f; } // output=1 thanks in advance
6 Respostas
+ 1
& means that the parameter is the address of a Int. This means that if you change the value of "r" inside the function, you're changing the value of i, outside the function, because they are pointing at the same address.
If you use f(int r) you're just passing the value of i, then, r will have the same value of i, but now if you change r inside the function, it will not change i, outside.
//The code is incomplete, no?
0
Это неправильный код
0
why is it wrong?
0
What does it mean: cout<<f;?
f is function so you must use () to call it. And what do you want to print? f returns void!
0
yes i know that. i just dont understand why the output is 1...
0
The real question is how do you print a function that returns nothing :/ You simply can't. The code should not even compile