I got this problem wrong on my homework, and I can't figure out why:
procedure Main is
X: Integer;
procedure Sub1 is
X: Integer;
begin - of Sub1
Put(X);
end; - of Sub1
procedure Sub2 is
X: Integer;
begin - of Sub2
X:=5;
Sub1
end; - of Sub2
begin -of Main
X:=12;
Sub2
end; - of Main
The Question is: Assume the following Ada program was compiled and execute using static-scoping rules. What value of X is printed in procedure of Sub1? What if it was under dyncamic scoping rules?
I got 12 and 5 respectively, but this was marked incorrect. Why?