New course! Every coder should learn Generative AI!
Try a free lesson+ 6
a and b are passed as references to x(). Within the function x(), a is first set to 3 and then set to 4 immediately after (note that the function is called with a, a as parameters, so only a will be changed). So after the function was executed, a will be 4, b will stay 7 (it wasn't passed to the function) and c as the return value of x will be 4+4=8
+ 2
#include <iostream>
using namespace std;
int x(int &y, int &z) {
y = 5;
z = 3;
return y + z;
}
int main() {
int a = 3;
int b = 7;
int c = x(a, a);
std::cout << a << b << c;
return 0;
}
Output is 376
But if we make change like
int c = x(a,b);
the output will be 378
hope it help u.