GATE | Gate IT 2007 | Question 33

Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods of parameter passing.

filter_none

edit
close

play_arrow

link
brightness_4
code

int i ;
program main ()
{
    int j = 60;
    i = 50;
    call f (i, j);
    print i, j;
}
procedure f (x, y)
{           
    i = 100;
    x = 10;
    y = y + i ;
}

chevron_right


Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?
(A) Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70
(B) Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70
(C) Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60
(D) Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70


Answer: (D)

Explanation: Call by value: A copy of parameters will be passed and whatever updations are performed will be valid only for that copy, leaving original values intact.

Call by reference: A link to original variables will be passed, by allowing the function to manipulate the original variables.


Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

3


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.