Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  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;
    }
    func 1 (x, y, z)
    {
        y = y + 4;
        z = x + y + z;
    }
    1. 10, 3
    2. 31, 3
    3. 27, 7
    4. None of these
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.



Your comments will be displayed only after manual approval.