Consider the following function written in the C syntax: int foo (int a, int b)
ID: 3797844 • Letter: C
Question
Consider the following function written in the C syntax: int foo (int a, int b) {a = b + 1; b = x * 2; return b - a;} In each of the cases below, assume that the initial values of the variables are x=1, y=2, and z=3. Write down the values of x, y and z after the following calls to foo (). If necessary, assume that output arguments are copied back to parameters in the left-to-right order. z = foo (x, y) where all parameters are passed by value z = foo (x, y) where all parameters are passed by reference z = foo(x, y) where all parameters are passed by value-result z = foo(y, y) where all parameters are passed by value z = foo(y, y) where all parameters are passed by reference z = foo(y, y) where all parameters are passed by value-resultExplanation / Answer
a)
x,y will remain unchanged, z will become -1
b)
x=3
y=6
z=3
c)
x=3
y=2
z=-1
d)
x=1
y=2
z=-1
e)
x=1
y=2
z=0
f)
x=1
y=2
z=-1
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.