1. Consider the following Ada skeletal program: procedure Main is X: Integer; pr
ID: 3633079 • Letter: 1
Question
1. Consider the following Ada skeletal program:procedure Main is
X: Integer;
procedure Sub3; -- declaration of Sub1. It allows Sub1 to call it.
procedure Sub1 is
X: Integer;
procedure Sub2 is
begin – of Sub2
…
end; -- of Sub2
begin – of Sub1
…
end; -- of Sub1
procedure Sub3 is
begin – of Sub3
…
end; -- Sub3
begin – of Main
…
end. -- of Main
Assume that the execution of this program is in the following unit order:
Main calls Sub1
Sub1 calls Sub2
Sub2 calls Sub3
a. Assuming static scoping, in the following points of execution which declaration of X is the correct one for a reference to X?
i. Sub1
ii. Sub2
iii. Sub3
b. Repeat (a) for dynamic scope.
Explanation / Answer
a) Assume the static scoping in the following points of execution of X is i. Sub1 gets the value of X from Sub1 ii. Sub2 gets the value of X from Sub1 iii. Sub3 gets the value of X from Main b) Let (a) for dynamic scoping i. Sub1 gets the value of X from Sub1 ii. Sub2 gets the value of X from Sub1 iii. Sub3 gets the value of X from Sub1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.