Question: 1) Consider the following program. What output is produced if static scoping is used? What output is produced if dynamic scoping is used? (4pts) int

1) Consider the following program. What output is produced if static scoping is used? What output is produced if dynamic scoping is used? (4pts)

int a, b; void p() { int a, p; a = 0; b = 1; p = 2; return p; } void print() { printf("%d %d ", a, b); } void q() { int b; a = 3; b = 4; print(); } int main() { a = p(); q(); return 0; }

Answer:

2) Consider the following program. What output is produced if static scoping is used? What output is produced if dynamic scoping is used? (4pts)

int a, b, c; void print() { printf("%d %d %d ", a, b, c); } void q() { int b; a = 5; b = 4; print(); } void p() { int a; a = 0; b = 1; c = a + b; q(); } int main() { p(); return 0; }

Answer:

3) Consider the following program. What output is produced if static scoping is used? (4pts)

procedure P0 var x: integer;

procedure P1(x: integer) begin x := x + 1; P2 end procedure P2 begin x := x * 2; end begin x := 1; P1(x); print x end

Answer:

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 Databases Questions!