Parameter-Passing

Question 1

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
Question 1 Explanation: 
Here, variable x of func1 points to address of variable y.
And variable y and z of func1 points to address of variable x.
Therefore, y = y+4 ⇒ y = 10+4 = 14
and z = x+y+z ⇒ z = 14+14+3 = 31
z will be stored back in k.
Hence, x=31 and y will remain as it is (y=3).
Hence, answer is (B).
There is 1 question to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access