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...
Consider the following Scheme function foo: (define (foo x) (cond ((null? x) 0) ((not (list? (car...
Consider the following Scheme function foo: (define (foo x) (cond ((null? x) 0) ((not (list? (car x))) (cond ((eq? x '()) (foo (car x))) (else (+ 1 (foo (cdr x)))))) (else (+ (foo (car x)) (foo (cdr x)))))) (8 pts) Explain what the function computes and how. Don’t just restate the function definition in English — explain the algorithm. Hint: not all the code in this function does something useful. (2 pts) Show the result of executing the expression (foo...
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)
Part 1 Here is some code: def foo(var): var = [] var.append("hello") var.append("world") list = ["bah"]...
Part 1 Here is some code: def foo(var): var = [] var.append("hello") var.append("world") list = ["bah"] foo(list) print(list) Which Option is correct? A) ["hello","world"] is output because python passes the list by reference and the list is changed inside the function. B) ["bah"] is output because python passes the list by value so changes to the list in the function are made to a separate list than the one that is passed in. C) ["bah"] is output because python passes...
      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...
Practice: Look at the following function header: def foo(a, b, c, d, e) answer the following...
Practice: Look at the following function header: def foo(a, b, c, d, e) answer the following questions: How many parameters this function has What is the name of this function If we call the function like this foo( 3, 2, 1, ‘c’, “Wdu”) what values will be assigned to a, b, c, d, e ? If we call function like this foo( 3, 2, 1, ‘c’, “Wdu”) what will be data types of a, b , c, d, and e.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT