Question: Consider the following code in a language that permits nested subprograms. subprog sub0() { var a, b, c; subprog sub1() var c; subprog sub2() {
Consider the following code in a language that permits nested subprograms.
subprog sub0() { var a, b, c; subprog sub1() var c; subprog sub2() { var a; a = 7; b = 14; c = 21; } //sub2 a = 5; b = 10; c = 15; sub2(); } //sub1 subprog sub3() { var b; a = 4; b = 8; c = 12 sub1(); } //sub3 a = 1; b = 2; c = 3; sub3(); } //sub0 for the program above I need to find the values of a, b, and c using static scoping and dynamic scoping. The answers should be:
Static Scoping: a = 5 b = 14 c = 12
Dynamic Scoping: a = 5 b = 2 c = 12
I have looked at the code over and over again and I just cannot comprehend how to do this. Can anyone please walk me through the steps clearly so that I can learn to do this?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
