Dynamic scoping


#1

What will be the output of the following pseudocode when parameters are passed by reference and dynamic scoping is assumed?
a=4;
void n(x)
{
x=x+a;
print(x);
}
void m(y)
{
a=1;
a=y-a;
n(a);
print(a);
}
void main()
{
m(a);
}


#2

Output:
7 3
Explanation: In main() m(4) is revoked because of global a.
now the new value of a will be 4-1 =3.now this value is used for revoking the function n(3).
now in n(3) x is calculated as x=3+4 because of global a. now 7 is printed first then 3 is printed.