Ask Question
28 July, 06:59

Consider the following pseudocode:

x : integer : = 1

y : integer : = 2

procedure add

x : = x + y

procedure second (P : procedure)

x : integer : = 2

P ()

procedure first

y : integer : = 3

second (add)

first ()

write integer (x)

(a) What does this program print if the language uses static scoping?

(b) What does it print if the language uses dynamic scoping with deep binding?

(c) What does it print if the language uses dynamic scoping with shallow binding?

+5
Answers (1)
  1. 28 July, 09:09
    0
    Part a: The program will print 3.

    Part b: The program will print 4

    Part c: The program will print 1.

    Explanation:

    Part a: As the scoping is static, the x integer has a value of 1 and the y integer has a value of 2 so the addition is 2+1=3.

    Part b: As the scoping is dynamic with deep binding, the x integer has a value of 2 and the y integer has a value of 2 so the addition is 2+2=4.

    Part c: As the scoping is dynamic with shallow binding, the x integer has a value of 1 so it will print 1.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Consider the following pseudocode: x : integer : = 1 y : integer : = 2 procedure add x : = x + y procedure second (P : procedure) x : ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers