Based on the following code and knowing that recursive calls are allowed, but NO
ID: 3590719 • Letter: B
Question
Based on the following code and knowing that recursive calls are allowed, but NOT forward references
-List potential procedures that could be called by the following procedures
fill in below chart for Main, Sub1, Sub2 and Sub3 based on the program at the bottom:
Again rembember that recursive calls are allowed but NOT forward references.
==========================================
main can call:_______________________________
sub1 can call:_______________________________
sub2 can call:_______________________________
sub3 can call:_______________________________
==========================================
proc main;
var w, x, y, z;
proc sub1;
var x, z;
X := 6; Z := 7;
x :=x + y * z;
end sub1;
proc sub2;
var w, x, y;
w := 11;
subl;
end sub2;
proc sub3;
var w;
w := 1 O; x := w+x; y := x + z + 2;
end sub3;
begin
w := O; x := 1; y := 3; z := 5;
sub2; sub3;
end main.
Explanation / Answer
Answer and explanation:
As per the code:
proc main;
var w, x, y, z;
proc sub1;
var x, z;
X := 6; Z := 7;
x :=x + y * z;
end sub1;
proc sub2;
var w, x, y;
w := 11;
subl;
end sub2;
proc sub3;
var w;
w := 1 O; x := w+x; y := x + z + 2;
end sub3;
begin
w := O; x := 1; y := 3; z := 5;
sub2; sub3;
end main.
in the procedure main:
sub2 and sub3 are getting called in the begin section . But when we call sub2 it is calling sub1 also so main can call sub1,sub2,sub3
in the proceudre sub2 ;sub1 is already getting called s sub2 can call sub1;
sub1 and sub3 cannot call anything as those both are local procedures
so the answer will be:
main can call:___________sub1,sub,2,sub3____________________
sub1 can call:___________nothing____________________
sub2 can call:_________________sub1______________
sub3 can call:________________nothing_______________
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.