(a) Consider the following pseudo-code (all data items are of type integer):…

PYQ GATE 1991Modified — slightly modified from the official paper; see the solution

(a) Consider the following pseudo-code (all data items are of type integer):

Procedure P (a, b, c);

a:=2;

c:=a+b;

end {P}

begin

x:=1

y:=5;

z:=100;

P(x,x*y,z);

Write (‘x=’,x,‘z=’,z)

end:

For reference passing of the expression x*y, assume its value is first placed in a fresh temporary integer and that temporary is passed by reference. Determine its output, if the parameters are passed to the procedure P by (i) value, (ii) reference and (iii) name.

(b) For the following pseudo-code, indicate the output, if (i) static scope rules and (ii) dynamic scope rules are used

Var a, b : integer;

Procedure P;

a:=5; b:=10

end {P};

procedure Q;

var a, b : integer;

P;

end {Q};

begin

a:=1; b:=2;

Q;

Write (‘a =’, a, ‘b=’,b)

end.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…