Question: Use the following code to emulate dynamic scope in C TO EMULATE FOLLOW THE ALGO BELOW Move lines 3-5 into main(). Do not leave any

Use the following code to emulate dynamic scope in C

Use the following code to emulate dynamic scope in C TO EMULATE

TO EMULATE FOLLOW THE ALGO BELOW

  1. Move lines 3-5 into main(). Do not leave any global variables.
  2. Since g() references a and b but does not define them, pass them in from main(). BUT you cannot just pass the values of a and b. You must pass the addresses of a and b.
  3. Likewise, f() references a, b, c so you need to pass addresses, from g() into f().

B scope.cx #include 2 3 int a = 10; 4 int b = 20; 5 int c = 30; 6 7 static void f(void) { 8 a += 5; 9 b += 5; 10 C += 5; 11 printf("f: a=&d b=%d c=%d ", a, b, c); 12 -} 13 14 static void g(void) { 15 int c = 40; 16 b+= 5; 17 C += 5; 18 f(); 19 printf("g: a=%d b=%d c=%d ", a, b, c); 20 } 21 22 pint main(int argc, char *argv[]) { 23 24 printf("main: a=%d b=%d c=%d ", a, b, c); 25 g()

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!