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. Programming in C programming-in-c + – Shubhanshu asked Nov 4, 2017 • edited Nov 5, 2017 by Shubhanshu Shubhanshu 2.1k views answer comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments Shubhanshu commented Nov 5, 2017 reply Follow Share about 'call by name' name goes mean i+j goes to x and it would be like i+j=2*10 so i don't think it would generate error. I think it will generate "lvalue required" error because i+j result an rvalue not lvalue. 1 votes 1 votes Rupendra Choudhary commented Nov 5, 2017 reply Follow Share sorry shubhanshu , i went wrong lvalue error certainly because we are assigning in an expression. yes! i can edit , but first you tell your goal. Then only i would be able to edit. 0 votes 0 votes Shubhanshu commented Nov 5, 2017 reply Follow Share Goal -> Just to understand, the basis of all four? which include any expression as it is different than passing directly variables. 0 votes 0 votes Please log in or register to add a comment.
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 Rupendra Choudhary answered Nov 10, 2017 Rupendra Choudhary comment Share Follow See all 0 reply Please log in or register to add a comment.