Answer : D
First refer the following question on Call-by-name parameter passing technique then solve this question.
https://gateoverflow.in/43575/gate2003-74?show=338119#a338119
Call by Name vs. Call by Need :
Assume X is the formal and e the corresponding actual expression.
Call-by-Name :
1. Delays evaluation of arguments past call until a reference to the formal.
2. Re-evaluates argument e on each reference to X in environment of caller.
3. No local variable X is allocated
Call-by-Need :
1. Delays evaluation of arguments past call until a reference to the formal.
2. Evaluates e on 1st reference in environment of caller & loads local variable X; no re-evaluation: subsequent references use local X
Since "Call by need" parameter passing technique, it is almost same as Call-by-name But the difference is that Actual argument is evaluated only once(on the first reference) and then that value is saved and re-used on further references But the actual argument is Not re-evaluated.
Caller function's Actual argument contains variable $i$ which clashes with called function P's local variable $i,$ hence, we rename called function P's local variable $i$ and change it to $i'.$
global int i=100, j=5;
void P(x) {
int i'=10; // this i' refers to the local variable i' in function P.
print(x+10); // this is first reference of x, so here, x= i+j, and these i,j refer to i,j in the caller function i.e. main function's environment
i'=200; // this i' refers to the local variable i' in function P.
j=20; // this j refers to j in the caller function i.e. main function's environment
print (x); // this x is second reference, so, we do not replace it with i+j because in call by need, we do not re-evaluate. So, we use the already calculated value of variable x and use it here.
}
main() {
P(i+j);
}
In case of Static scoping : 115, 105
In case of Dynamic scoping : 115, 105
Note that there are no local variable $i,j$ in main function, so, when we say that $i,j$ refer to the $i,j$ in main's environment , we mean that If $i,j$ were accessed/updated in main function then depending on the scoping, which $i,j$ would they refer.
Here, in this question, in both static and dynamic scoping case, $i,j$ will refer to the Global variables.
And in function P, in the 4th statement (i.e. $j = 20$), the Global variable $j$ will be updated.