edited by
547 views
1 votes
1 votes

edited by

1 Answer

Best answer
1 votes
1 votes

Answer is B.

In Static Scoping, if a variable is not defined in the Local space, it is looked in Globle Space. OR Static scoping means that x refers to the x declared innermost scope of declaration that has one

In Dynamic Scoping,  if a variable is not found in the Local space , it is looked in the place, where it recursive called. OR Dynamic scoping means that x refers to the x declared in the most recent frame of the call-stack the has one.

In Static
main() assign x = 2 that is globally declare and then call f2().           

f2() have its own x so it change its own , then it call f1().

 In f1() x is not declared so it use global x, and make it 1 so finally value of x in Static scoping is 1.

In Dynamic

First main assign value of x = 2 then call f2(),

f2() have its own x to its assign x=3 then f2() call f1().

f1() not find x in local space so it is looked in the place, where it recursive called means in f2().

In f1() when wo assign value of x then it change x of f2() NOT x of main.(DYNAMIC SCOPING)
So finally in main when "print x" occur then it print 2.

Hope you understand. Thanks

selected by

Related questions

1 votes
1 votes
1 answer
1