Question: You will be given multiple choices for each answer, one being None of the others . You will choose the answer that matches yours or

You will be given multiple choices for each answer, one being None of the others. You will choose the answer that matches yours or None if that is the case.
======================================================
Q1. For the following program FOO, assuming each scoping method:
a) Static and
b) Dynamic Scoping,
show the output x at locations****** The program execution begins execution in MAIN.
PROGRAM FOO()
VAR x : integer;// this is global
//========= A =============
PROCEDURE A()
VAR d : integer;
BEGIN
x :=5;
d :=6;
B();// call to B
writeln(x);// output the value of x ***
END // procedure A
//======= B =============
PROCEDURE B() BEGIN
writeln(x);// output the value of x **
END // procedure B
//======= MAIN =====================
PROCEDURE MAIN()
VAR x : integer;
BEGIN//(Program starts here
x :=10;
A();// call to A
writeln(x);// output the value of x *
END
END. // program FOO
a) Static scoping? X:*5**5***10
b) Dynamic scoping? X:*5**5***5
Q2. For the program in Q1, assuming Dynamic Scoping, what would be the referencing environment for statements when executing the first line (so after the BEGIN) in
a) procedure A?(include only variable names)
b) procedure B?(include only variable names)
c) procedure MAIN? (include only variable names)
Q3. True or False
a) The declaration of a local variable with the same name as a non-local variable can only hide the non-local variable in the local scope when using Static Scoping but not when using Dynamic Scoping.
b) A globally declared variable will always be visible everywhere in a program.
c) Run-time overhead is the main reason Dynamic scoping is not chosen over Static scoping.
d) The type and value are always bound to a variable name at the same time.
e) A Heap-Dynamic variable typically requires the user to create a Reference or Pointer typed variable to allow them to be accessed by the user.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!