+ 2
Can somebody please explain this step-by-step?
#include <iostream> int f(int &a, int &b) { a = 3; b = 4; return a + b; } int main() { int a = 1; int b = 2; int c = f(a, a); std::cout << a << b << c; } Why output is 428?
2 Réponses
+ 8
When both arguments are a, you need to remember that the same variable is controlled, and one variable can only hold one value.
The function would literally assign 3 to a, and then override the previous assignment with 4 to a, and then return 4+4.
Hence the output is 428
+ 1
I got it, thanks!