[Solved] C++ – Calculating final values of x and y with a specific function


For starters you could just run the code… but otherwise we can try and predict the output.

For starters the function f has two parameters, i and j. The & Infront of the j means that the value of the function input is passed by reference (the value of the variable will be edited).

So now let’s evaluate the function with inputs 4, 7. We get:

j = 4+1 = 5
i = 10
j += i, j = 15

Because the variable y was passed by reference, its value will become 15. The variable x was passed by value, so it doesn’t get affected and thus stays as 4.

0

solved C++ – Calculating final values of x and y with a specific function