retagged by
8,485 views
9 9 votes

Consider the following program in a language that has dynamic scooping:

var x: real;
procedure show:
    begin print(x);end;
procedure small;
    var x: real;
        begin x: = 0.125; show; end;
begin x:=0.25
    show; small
    end.

Then the output of the program is:

  1. 0.125 0.125
  2. 0.25 0.25
  3. 0.25 0.125
  4. 0.125 0.25

3 Answers

Best answer
24 24 votes
ans c)

In dynamic scoping, if a variable is not found in the local scope it is looked up on at the function from which the call is made.
selected by
0 0 votes

Start from the Last Line.

 1.   x := 0.25 (global)

 2.  show() => prints global x = 0.25

 3.  small():

 4.  Local x := 0.125 

    =>  show() = looks in small's scope  
    =>  x = 0.125

Output: 0.25 0.125

 

Answer:
Position:
Show:

Related questions

43 43 votes
6 answers 6 answers
16.8k
16.8k views
Kathleen asked Sep 23, 2014
16,827 views
The number of binary strings of $n$ zeros and $k$ ones in which no two ones are adjacent is$^{n-1}C_k$$^nC_k$$^nC_{k+1}$None of the above
1 1 vote
1 answers 1 answer
2.6k
2.6k views
Kathleen asked Oct 5, 2014
2,619 views
Consider the program below:Program main: var r:integer; procedure two: begin write (r); end procedure one: var r:integer; begin r:=5; two; end begin r:=2; two; one; two; ...
2 2 votes
2 2 answers
7.6k
7.6k views
Kathleen asked Sep 17, 2014
7,640 views
Consider the following class definitions in a hypothetical Object Oriented language that supports inheritance and uses dynamic binding. The language should not be assumed...
7 7 votes
1 answers 1 answer
6.7k
6.7k views
Ishrat Jahan asked Oct 29, 2014
6,715 views
Early binding refers to a binding performed at compile time and late binding refers to a binding performed at execution time. Consider the following statements:Static sco...