Open In App

GATE | Gate IT 2007 | Question 33

Like Article
Like
Save
Share
Report

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.




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 ;
}


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


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads