in Compiler Design
886 views
3 votes
3 votes

How to solve any dynamic scoping question . Plz describe in detail.

in Compiler Design
886 views

1 Answer

0 votes
0 votes
answer is c

first time when the plus(25) is called then,in plus function x=25, but a is not defined .if this was static scoping then it would have taken value 10 of global variable,but since it is dynamic scoping so it will find a in the function which is stacked below this function which is main function so ,here a is 1 hence 26 will be printed.

then a =3 then again plus(a) is called here x=3 a=3 hence 6 will be printed

inc() will do nothing to a as a is not static it is local variable so a will be 3 and will print 3 .last plus(a) will print 6 similarly

Related questions