-
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;
}
func 1 (x, y, z)
{
y = y + 4;
z = x + y + z;
}
-
- 10, 3
- 31, 3
- 27, 7
- None of these
- 10, 3
Correct Option: B
Note the order in which parameters are passed. Inside func1(), x will actually refer to y of main (); and y and z will refer to x of main (). The statement y = y + 4; will result in 14 and statement z = x + y + z will make z = 3 + 14 + 14 = 31 (because y and z point to same variable x of main). Since z refers to x of main(), main will print 31.