Question

In: Computer Science

Determine the output of the following program: var x; function bar() { writeln(x); } function foo()...

Determine the output of the following program:
var x;
function bar() {
    writeln(x);
}
function foo() {
    var x;
    x = 3;
    bar();
}
function oof() {
    var x;
    x = 7;
    foo();
}
x = 5;
oof();

(a) if the static scoping rule is used? What is the reason?.
(b) if the dynamic scoping rule is used? What is the reason?.

Solutions

Expert Solution

SOL:


Related Solutions

QUESTION 1 Consider the following program: var x = 0; function sub1() {    var x =...
QUESTION 1 Consider the following program: var x = 0; function sub1() {    var x = 1;    function sub2() {       function sub3() {          print x;       }       sub3();    }    function sub4() {       var x = 2;       sub2();      }    sub4(); } sub1(); If this code uses static scoping, when it is executed what is printed? 0 1 2 QUESTION 2 Consider the following program: var x = 0; function sub1() {    var x = 1;    function sub2() {       function sub3() {          print...
In C++, write a function that takes in as inputs two arrays, foo and bar, and...
In C++, write a function that takes in as inputs two arrays, foo and bar, and their respective array sizes. The function should then output the concatenation of the two arrays as a singly linked list. You may assume that you are provided a singly linked list header file.
Prove Var(|X|) <= Var(X)
Prove Var(|X|) <= Var(X)
      Show that     Var(x-a/)=1/h^2 Var(x)
      Show that     Var(x-a/)=1/h^2 Var(x)
For the given function determine the following: f (x) = (sin x + cos x) 2...
For the given function determine the following: f (x) = (sin x + cos x) 2 ; [−π,π] a) Find the intervals where f(x) is increasing, and decreasing b) Find the intervals where f(x) is concave up, and concave down c) Find the x-coordinate of all inflection points
Consider the function f(x) = x 4 − 4x 2 . Determine the following: • The...
Consider the function f(x) = x 4 − 4x 2 . Determine the following: • The (x,y) coordinate pairs of the local minima and local maxima. • The (x,y) coordinate pair of the absolute minimum and absolute maximum, should they exist. If the absolute min/max is obtained at multiple points, list all of them. • The intervals of increasing and decreasing. • The intervals of concavity. That is, explain exactly where this function is convex and exactly where this function...
Consider the following production function: x = f(l,k) = lb kb where x is the output,...
Consider the following production function: x = f(l,k) = lb kb where x is the output, l is the labour input, k is the capital input, and b is a positive constant. Suppose b < 1/2. (a) Set up the cost minimization problem and solve for the conditional labour and conditional capital demand functions. Let w and r be the wage rate and rental cost of capital respectively. (b) Using your answer in (a), derive the cost function and simplify...
The output of an engineering system as a function of position (x) is modeled by the...
The output of an engineering system as a function of position (x) is modeled by the differential equation y'' + 9y = 5cos(2x) - 10sin(2x), where y = f(x), y(π/2) = 2, and y'(π/2) = 6. Solve this differential equation to obtain an expression for y as a function of x (i.e., to obtain the function y(x)).
E(Y) = 4, E(X) = E(Y+2), Var(X) = 5, Var(Y) = Var(2X+2) a. What is E(2X...
E(Y) = 4, E(X) = E(Y+2), Var(X) = 5, Var(Y) = Var(2X+2) a. What is E(2X -2Y)? b. What is Var(2X-Y+2)? c. What is SD(3Y-3X)? 2) In a large community, 65% of the residents want to host an autumn community fair. The rest of the residents answer either disagree or no opinion on this proposal. A sample of 18 residents was randomly chosen and asked for their opinions. a) What is th probability that the residents answer either disagree or...
Given: E[x] = 4, E[y] = 6, Var(x) = 2, Var(y) = 1, and cov(x,y) =...
Given: E[x] = 4, E[y] = 6, Var(x) = 2, Var(y) = 1, and cov(x,y) = 0.2 Find a lower bound on (5 < x + y < 10). State the theorem used.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT