1.4k views

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
edited | 1.4k views

i think ans should be A.

as per call by value concept. $X$ in the procedure FIND is a local variable. no change will be refleced in global var $X$.

edited by
0
but no where mentioned that call by value is in use here.
0
yaa, they have not mentioned anything about any parameter passing technique.

then which technique should we take default, if they have not mentioned anything?
+5
If that happens mark will be given for all. For this question, it might have been mentioned but lost while the question was copied. We don't have any original GATE question paper before 2007. So, those questions available online might not be exactly the same as were asked in GATE.

If the code is C language, then you must assume call-by-value.
0
ok, thank you.
0
Can we pass an integer value to a function having real parameter? Wouldn't it give an error?
0

@Arjun sir . @Shaik Masthan..by static scoping..which is the default case...why not the answer is square root 2... since variable definition is not found in local scope so global variable is considered...

In similar ques ..we have used this feature  static scoping https://gateoverflow.in/43603/gate1991-09b

2..because it is call by value..so value doesn't gets changed.
0
Can you know explain me?
+1
Here we are not passing the address of x.So it does not get changed.Only a copy of it is made thats why it is 2.
+1 vote
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.
It goes into an infinite loop as the 2nd prog. goes on calling the 1st prog. And it never reaches the writeline ..so itdoesnt print anything
0
It is calling only once rt?
0
sir, isn't the correct option should be b).only..because the function is being called only once...
+1
Yes. But there can also be a compile time error (in strongly typed languages) since an integer is passed to a function expecting real.
0
how infinite loop?
0
In strongly typed languages, during run-time the type will be verified right?

1