when static scoping is used :
x is global with value 10;
Part2(&x)
another x is created with local scope and static : x=15;
*b=*b *x; value of global x = 150;
Part1(&x) // this is calling to part1 by passing local x address
*a+=x++; // here += is RL assosiative so first x++ will be evaluated then += and this is static scoping so first we will search in local x then global x so no local x to part1 is there then go to global x and increment it, now global x=151.
*a+= 150;
*a=15+150=165; local x=165;
print(165);
//part2 print(local x = 165)
Part1(&x):// global x=151
*a+=151; global x=152
*a=*a+151; 152+151=303 ; global x=303
print(303);
When Dynamic scoping is used: https://courses.cs.washington.edu/courses/cse341/03wi/imperative/scoping.html
global x=10;
Part2(&x):
another x is created with local scope and static : x=15;
*b=*b *x; value of global x = 150;
Part1(&x) // this is calling to part1 by passing local x address
*a+=x++; // this is dynamic scoping so first value it will search in local scope then in its caller function so at part2 it will get x=15;
*a+=15; now post increment x=16
*a=16+15=31; local x=31
print(31);
print(31)
Part1(&x):// global x=150
*a+=150; here x will find x in global so x=151
*a=151+150=301
print(301);
with Static scoping :
165
165
303
with dynamic scoping :
31
31
301