Related Articles

# GATE | GATE-CS-2001 | Question 42

• Last Updated : 28 Jun, 2021

What is printed by the print statements in the program P1 assuming call by reference parameter passing?

```Program P1()
{
x = 10;
y = 3;
func1(y,x,x);
print x;
print y;
}
func1(x,y,z)
{
y = y+4;
z = x+y+z;
}```

(A) 10, 3
(B) 31, 3
(C) 27, 7
(D) None of the above

Explanation: Here, we are passing the variables by call by reference. This means that the changes that we will make in the parameter would be reflected in the passed argument.

Here, the first variable passed in the function func1 (i.e., y) points to the address of the variable x.

Similarly, the second variable passed in the function func1 (i.e., x) points to the address of the variable y and the third variable passed in the function func1 (i.e., x) points to the address of the variable z.

So, we have y = y + 4 ⇒ y = 10 + 4 = 14

and z = x + y + z ⇒ z = 14 + 14 + 3 = 31

z will be returned to x. So, x = 31 and y will remain 3.

Thus, the correct choice is B.

Please comment below if you find anything wrong in the above post.

Quiz of this Question

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up