You are on page 1of 5

CS 112 Laboratory

Activity 1

1. (1pt) True or false: A binding cannot be destroyed before the object it binds is destroyed.

False
2. (1pt) True or false: In C, static allocation does not allow for the storage of objects that
dynamically change in size.

True

3. (1pt) What rule does a PL follow where the bindings created during a subroutine call are
not destroyed upon exiting that subroutine?

DYNAMIC BINDING

4. (1pt) How could a program that seemingly occupies a small memory space at runtime
actually have a large reference environment that occupies a lot of memory?

There are instances where there are branches of code that are not executed at run time.
E.g. Only the applicable branch of code will execute in an if else statement no matter how
long branching the conditions are.

A programmer must take it into consideration at compile time to prepare for all possible
branches of decisions that may occur in the future. Thus, taking up more memory space
at compiling, but executing only one of those decision branches at compile time.

5. (1pt) What control structure can cause 10% of your physical code to run at 90% of time?
Explain your answer.

IF-ELSE (BRANCH STRUCTURE)


- Branch structure will offer allow programmer to create multiple scenarios and
instances but will only execute 1 branch.

6. (3pts) When is the binding time of the following objects? Choose your answers from these
options: language design time, compile time, or binding time.
a. Data layout plan - language design time
b. String size - compile time
c. Data type - compile time

7. (2pts) Consider the following JavaScript program:


CS 112 Laboratory
Activity 1

a. What is printed by the program if it follows static scope? x = 5; (global scope)

b. Dynamic scope? x = 10; (local scope)

8. (2pts) Consider the following JavaScript program:

OPTIONS:
a. x in main() (global)
b. x in f1() (local)

Assuming static scoping:


a. Which declaration of x is referred when calling f1()? x in f1()
b. When calling f2() from f1()? x in main()
c. When calling f3() from f2()? x in main()

Assuming dynamic scoping:


d. Which declaration of x is referred when calling f1()? x in f1()
e. When calling f2() from f1()? x in f1()
f. When calling f3() from f2()? x in f1()

9.
CS 112 Laboratory
Activity 1
CS 112 Laboratory
Activity 1
CS 112 Laboratory
Activity 1

You might also like