Please explain the answer as well. A. If x is an int variable with an initial va
ID: 3734639 • Letter: P
Question
Please explain the answer as well.
A. If x is an int variable with an initial value 5, find the value of x upon the return of the call f(x, x) to the following C++ function.
void f(int& x, int& y) {
x = x + y;
y = x - y;
x = x – y;
}
B. If x is an integer variable with an initial value 5, find the value of x upon the return of the call f(x, x) to the following Ada procedure, assuming pass by value-result.
procedure f(x, y: in out Integer) is begin
x := x + y;
y := x - y;
x := x – y;
end f;
Explanation / Answer
Final value of x will be 5.
Below is the explanation.
As initial value of x is 5.
x= 5+5 = 10; (x value will be update to 10)
y=10-5 = 5; ( As x value is 10 and y still holds 5 )
x=10-5 = 5 (Final value)