Question: Consider the following pseudo - code, assuming nested subroutines and static scoping: 1 int main ( ) { 2 int x = 3 ; 3

Consider the following pseudo-code, assuming nested subroutines and static scoping:
1 int main (){
2 int x =3;
3 int y =2;
4 int f1( int b ){
5 int f2( int n ){
6 return n +3;
7}
8 b = f2( y )+2* b ;
9 return b ;
10}
11
12 int f3( int a ){
13 return f1( a );
14}
15 print f3( f1( x ));
16}
1. What does the program print?
2. Draw a diagram of the runtime stack when function f2 has been called for the last
time. For each frame, show the static and dynamic links.
3. Refer to the runtime stack, briefly explain how function f1 finds variable y.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!