edited by
2,093 views
0 votes
0 votes
void main()
{
    int i = 10, j = 20;
    evaluate(i+j);
}
void evaluate(int x)
{
    print(x);
    x = 2 * 10; // in this I think call-by-name give lvalue error.
    print(x);
}

I think call-by-reference will also give an error, because call-by-reference needs an address to point.

Evaluate the result using

1. call-by-reference

2. call-by-name

3. call-by-need

4. call-by-value.

edited by

1 Answer

1 votes
1 votes

Call by reference :- Here at calling time addresses of variables are passes and as we work here on address(logical address) of variable , any change done to the value on this address is at the moment functionalized.

Call by value result(copy restore or copy reference) :- it's special case of call by reference. o/p of call by value result is almost always same as call by reference except few cases(i mentioned those in my examples).Actually when we send ame argument twice (aliasing)under call by reference , writing to one will affect other but under call by copy restore , it wont happen.

Call by name :-Here just substitute formal parameter with actual parameter , where ever they appeared in called function.

i am attaching link , where you will get some solved questions for above three calling techniques.If you have any doubt , just comment.

Another thing is by default C/C++ support call by value, for call by reference , we have to manually pass the address(like we do using & and *).

https://drive.google.com/open?id=1Stfy-Q6AltW4uDMe-QFmcOAqkfBKDK6g

https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_copy-restore

http://www.lix.polytechnique.fr/~catuscia/teaching/cg428/02Spring/lecture_notes/L07.1.html

https://courses.cs.washington.edu/courses/cse505/99au/imperative/parameters.html

   

                                                            

   

  

Related questions

0 votes
0 votes
1 answer
2
0 votes
0 votes
0 answers
3
Gate Fever asked Nov 26, 2018
870 views
what should be the output for call by name and call by copy restore??i know the basic meaning of call by name and call by copyrestore but am unable to solve the question!...
0 votes
0 votes
1 answer
4