Aug2016 cs Q21

0. Assume that the program ‘P’ is implementing parameter passing with ‘call by reference’. What will be printed by following print statements in P?
Program P()
{
x = 10;
y = 3;
funb (y, x, x)
print x;
print y;
}f
unb (x, y, z)
{
y = y + 4;
z = x + y + z;

  • Option : B
  • Explanation :
    Program P( )
    {
    x = 10;
    y = 3;
    funb (y, x, x)
    print x;
    print y;
    }
    funb (x, y, z)
    {
    y = y + 4;
    z = x + y + z;
    }
    Since, It is call by reference then address will be pass as argument:
    i.e. P( )
    {
    x = 10;
    y = 3;
    funb (&y, &x, &x)
    print x;
    print y;
    }
    funb (x, y, z) //funb (&y, &x, &x) //
    {
    y = y + 4; //at &x 14 will be assigned //
    z = x + y + z; // Now &x will be assigned with 3 + 14 + 14 = 31.
    }
    There is no change in y and x is updated twice when printf called it will print x = 31 and y = 3.
    So, option (B) is correct.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *