Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: call by name : clashing variables in called procedure

Mahakp:

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);
}

  1. Will the variable I declared in function P get renamed before execution ?
  2. Which I (global or local) is accessed by x in print(x + 10)?
  3. Which I (global or local) will get updated by (i = 200)?
  4. What will be the output of the second print statement (220 or 120)?


Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: call by name : clashing variables in called procedure

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×