Ask Question
9 March, 22:57

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?

+3
Answers (1)
  1. 9 March, 23:25
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers