Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2.)Assume the following Ada program was compiled and executed using static scope

ID: 663106 • Letter: 2

Question

2.)Assume the following Ada program was compiled and executed using static scope rules. What value of X is printed in procedure Sub1? Under dynamic scoping rules, what value of X is printed in procedure Sub1?

procedure Main is

   X: Integer;

   procedure Sub1 is

        begin      -- of Sub1

        Put(X);

        end;       -- of Sub1

   procedure Sub2 is

        X: Integer;

        begin      -- of Sub2

        X := 10;

        Sub1

        end;      -- of Sub2

   begin      -- of Main

   X := 5;

   Sub2;

   end;           -- of Main

Explanation / Answer

Execution using static rule :

We begin from main :

i.In Sub1, Put(X) is called which displays the value of X as 5;

So the output in case of Static rule is X=5;                    

Rule followed :

When the program encounter a variable say X in this case it does the following :