518 views
4 votes
4 votes

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 ) ?

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
1
Abhisek Tiwari 4 asked Jan 3, 2019
236 views
main(){int ar[5],a=0; ar={4,5,6,0,3}fun(ar[a],ar[ar[a])}// will the called function be resolved to fun(0,3) at compile time ?? [Code Optimization:Folding]
0 votes
0 votes
1 answer
2