Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

GATE | Gate IT 2007 | Question 33

  • Difficulty Level : Medium
  • Last Updated : 28 Jun, 2021

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.

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.




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

My Personal Notes arrow_drop_up
Recommended Articles
Page :