Question

Given the following pseudo-code below with nested subprograms, (a) Under static-scoping rules, what will be printed...

Given the following pseudo-code below with nested subprograms,

(a) Under static-scoping rules, what will be printed out?

(b) Under dynamic-scoping rules, what will be printed out?

(c) Name a disadvantage of dynamic scoping.

 var x, y;
                       function  sub2() {
                                              var y;
                                              y = 10;
                                              document.write("x = " + x + "" + “y = “ + y + “ “);
                                              
                       }
                       function  sub1() {
                                              var x;
                                              x = 30;
                                              document.write("x = " + x + "" + “y = “ + y + “ “);        
                                              sub2();
                                              document.write("x = " + x + "" + “y = “ + y + “ “);
                       }
                       
                       x = 20;
                    y = 50;
                       sub1();

Homework Answers

Answer #1

Static Scoping: Look for the definition within a block then enclosing block then global variables.

Dynamic Scoping: Look for the definition within a block then enclosing block then calling Function then global variables.

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
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...
Given the nested object below, provide the JavaScript code to navigate to the "Sugar" value (highlighted...
Given the nested object below, provide the JavaScript code to navigate to the "Sugar" value (highlighted below) and print it to the console. var food = { id: "0001", type: "donut", name: "Cake", ppu: 0.55, base: { batters: [ { id: "1001", type: "Regular" }, { id: "1003", type: "Blueberry" }, { id: "1004", type: "Devil's Food" } ] }, topping: [ { id: "5001", type: "None" }, { id: "5002", type: "Glazed" }, { id: "5005", type: "Sugar" },...
Given the following code: int x = 0; int y = 10; int *ptr = &x;...
Given the following code: int x = 0; int y = 10; int *ptr = &x; *ptr = -55; x += -52; ptr = &y; *ptr += 52; printf("%d\n", x); What is printed to the screen?
Complete the following function (detailed instructions are given below the code): private static int predecessor(int array[],...
Complete the following function (detailed instructions are given below the code): private static int predecessor(int array[], int arrayLen, int key) { // Complete this function. } Given a set of numbers, the predecessor of a number x is the highest number in the set that is less than or equal to x. Thus, if I have the set {6; 9; 10; 13; 22; 31; 34; 88}, then the predecessor of 31 is 31 itself, whereas the predecessor of 30 is...
In the following C code, Which variable if NOT of primitive data type? A. a B....
In the following C code, Which variable if NOT of primitive data type? A. a B. b C. c D. d int a = 10; double b = 20.0; float c = false; char d[5] = "Hello"; // here we define a string In programming language C, the implementation of a string data type is limited dynamic length, which means the length of a string variable is fixed once it has been defined. A. True B. False In C# programming...
given the discrete probability distribution below: x 10 20 30 40 50 P(x) 0.3 0.05 0.1...
given the discrete probability distribution below: x 10 20 30 40 50 P(x) 0.3 0.05 0.1 0.05 0.2 calculate: a. E(x) b. Var(x) c. σx
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 >=...
19) What will be the output of the following JavaScript code? for(var x = 1; x...
19) What will be the output of the following JavaScript code? for(var x = 1; x < 5; x++) console.log(x); a) 11111 b) 12345 c) 1234 d) 5555 20) What will be the output of the following JavaScript code? var x = 0 do{ console.log(x) }while(x > 0) a) 0 b) null c) 1 d) No output quiz 3 4) Which of the following is an entry point of ASP.NET Core application? a) Main method of Program class b) Configure...
The 1991 exports and imports by industry code are given in the following table. What is...
The 1991 exports and imports by industry code are given in the following table. What is the approximate slope coefficient estimate b of the regression of exports as a function of imports? SIC Code Exports (millions of dollars) Imports (millions of dollars) 3088 20 27 3261 41 74 3272 24 70 3275 54 32 3296 85 30 3441 54 22 3448 72 25 Question 15 options: A) –0.5. B) –5.0. C) –0.3. D) –3.0. E) 0.4.
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT