In call by name : In general, the effect of pass-by-name is to textually substitute the argument expressions in a procedure call for the corresponding parameters in the body of the procedure.
Technically, if any of the variables in the called procedure clash with the caller's variables, they must be renamed uniquely before substitution.
ref : http://www.cs.sfu.ca/~cameron/Teaching/383/PassByName.html
Now consider the following code :
global int i = 100, j = 5;
void P(x)
{
int i = 10;
print(x + 10);
i = 200;
j = 20;
print(x);
}
main()
{
P(i + j);
}
- Will the variable i declared in function P get renamed before execution ?
- Which i ( global or local ) is accessed by x in print(x + 10) ?
- Which i ( global or local ) will get updated by (i = 200) ?
- What will be the output of the second print statement (220 or 120 ) ?