Dynamic and static Scoping program differences

Static scoping means that x refers to the x declared innermost scope of declaration that has one. Since h is declared inside the global scope, the innermost x is the one in the global scope(it has no access to the xs in f and g, since it was not declared inside them), so the program prints 14 twice.

Dynamic scoping means that x refers to the x declared in the most recent frame of the call-stack the has one. If C used dynamic scoping, h would use the x from either f or g – whichever one that called it – so the program would print 13 and 12.

Leave a Comment