recategorized by
6,942 views
13 votes
13 votes

What is the value of $X$ 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.
  1. $2$
  2. $\sqrt{2}$
  3. Run time error
  4. None of the above
recategorized by

6 Answers

16 votes
16 votes

Answer should be A.

As per call by value concept. $X$ in the procedure FIND is a local variable and so no change will be reflected in the global var $X$.

edited by
3 votes
3 votes
The program is in Pascal, for which default function call is call-by-value, so value 2 is passed to the procedure FIND which performs operation on it's local variable X (which is defined as real) therefore changes would not be reflected on the global variable, the value of X=2 will thus be written/printed.
2 votes
2 votes
2..because it is call by value..so value doesn't gets changed.
1 votes
1 votes

the answer is D. None of the above

as in the line –        

begin
    X:=2

there is no end semi-colon so there will be compilation error(semantic error);

hence option D

Answer:

Related questions

44 votes
44 votes
1 answer
2
15 votes
15 votes
3 answers
3
Kathleen asked Oct 8, 2014
4,570 views
What are $x$ and $y$ in the following macro definition?macro Add x, y Load y Mul x Store y end macroVariablesIdentifiersActual parametersFormal parameters
5 votes
5 votes
1 answer
4