What is printed by the following program, assuming call-by-reference parameter…

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

What is printed by the following program, assuming call-by-reference parameter passing for procedure P? Assume the expression a+b is evaluated once into a temporary cell that x references.

program Main(inout, output);
var a, b:integer;
    procedure P(x, y, z:integer);
    begin
        y:=y+1;
        z:=x+x
    end P;
begin
    a:=2; b:=3;
    P(a+b, a, a);
    Write(a)
end.

Sign up free to check your answer

Sign up free

Explore the full course: Compiler Design

Loading lesson…