Question

4. Consider the following program, written in JavaScript-like syntax: // main program var x, y, z...

4. Consider the following program, written in JavaScript-like syntax: // main program var x, y, z function sub1() { var a, y, z; . . . } function sub2() { var a, b, z; . . . } function sub3() { var a, x, w; . . . } Given the following calling sequences and assuming that dynamic scoping is used, what variables are visible during execution of the last subprogram activated? Include with each visible variable the name of the unit where it is declared. a. main calls sub1; sub1 calls sub2; sub2 calls sub3 b. main calls sub1; sub1 calls sub3 c. main calls sub2; sub2 calls sub3; sub3 calls sub1 d. main calls sub3; sub3 calls sub1 e. main calls sub1; sub1 calls sub3; sub3 calls sub2 f. main calls sub3; sub3 calls sub2; sub2 calls sub1

Homework Answers

Answer #1

a. main calls sub1; sub1 calls sub2; sub2 calls sub3

   = axw in sub3.b , z in sub2, y in sub1

b. main calls sub1; sub1 calls sub3

     = axw in sub3, yz in sub1

c. main calls sub2; sub2 calls sub3; sub3 calls sub1

   = ayz in sub1, xw in sub3, b in sub2

d. main calls sub3; sub3 calls sub1

   = ayz in sub1, xw in sub3

e. main calls sub1; sub1 calls sub3; sub3 calls sub2

= abz in sub2, xw in sub3, y in sub1

f. main calls sub3; sub3 calls sub2; sub2 calls sub1

   = ayz in sub1, b in sub2, xw in sub3

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
2. Consider the following program written in C syntax: void swap(int a, int b) {   ...
2. Consider the following program written in C syntax: void swap(int a, int b) {    int temp;    temp = a;    a = b;    b = temp; } void main() {    int value = 2, list[5] = {1, 3, 5, 7, 9};    swap(value, list[0]);    swap(list[0], list[1]);    swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three...
Consider the following program listing that is written in the C Language: #include <msp430.h> void main(void);...
Consider the following program listing that is written in the C Language: #include <msp430.h> void main(void); { WDTCTL = WDTPW|WDTHOLD; unsigned char a=0x14; unsigned char b=0xDC; unsigned char c,d,e,f; c = a^b; d = a|b; e = ~d; f = ~e; while(1); } 1) Are the declared data types local or global variables? 2) Perform bitwise logical analysis to determine the unknown values of the given logic expressions. 3) Show the correct addresses and contents for all variables in the...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT