In static scoping, if a variable is not found (variable definition - memory allocation) in the local scope (current function, which includes the current block, then parent block etc.), it is looked upon in global scope. In dynamic scoping, if a variable is not found in local scope, it is looked upon in the function which called the current executing one.
- $a = 5, b = 10$. main is using global variables. P is also using global variables.
- $a = 1, b = 2$. main is using global variables. P is using the local variables defined in Q.
(The modification in Q, happens to the variables in P but in main we use the global variables)