Skip to content
Official PYQ · 1995

GATE CS 1995 Q2.4 — Runtime Environments

Explain with AI

What is the value of XX printed by the following program?

program COMPUTE (input, output);
var X:integer;
procedure FIND (X:real);
    begin
        X:=sqrt(X);
    end;
begin
    X:=2
    FIND(X);
    writeln(X);
end.
Choose one option
View worked solution

Answer: A

In Pascal, parameters are passed by value by default, unless they are explicitly declared with the var keyword (which denotes call-by-reference).

Let's trace the execution of the program:

  1. The global variable X of type integer is initialized to 2 in the main program block:
    X := 2;
  2. The procedure FIND(X) is called. Since the parameter in procedure FIND (X:real) is passed by value, a local copy of X is created for the procedure.
  3. Inside FIND, the local variable X is updated to 2\sqrt{2}:
    X := sqrt(X);
    This modification is local to the procedure and does not affect the global variable X.
  4. After the procedure call terminates, control returns to the main program, where writeln(X) is executed.
  5. Since the global variable X remains unchanged, the value printed is 2.

Therefore, the correct option is A.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Runtime Environments questions