1 votes 1 votes int i = 1; int main() { int a[]= { 0,1, 2} ; f(a[i], i); printf("%d", a[i]); } void f(int x, int y) { y++; x=5*i; } In above function f() uses " call by name" technique, what is the output printed? a) 2 b) 10 c) 5 d) 1 Programming in C programming parameter-passing + – Isha Karn asked Dec 9, 2014 Isha Karn 982 views answer comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments Arjun commented Dec 12, 2014 reply Follow Share @Isha-karn which place are these parameter passing questions taken from? 1 votes 1 votes sumit kumar commented Dec 12, 2014 reply Follow Share @shyam you are just taking this call by text l to be same as call by value.both are different!!! http://www.cs.rit.edu/~rpj/courses/plc/lab4/lab47.html#Q12 0 votes 0 votes Isha Karn commented Dec 12, 2014 reply Follow Share @Arjun Sir these questions are taken from test papers of a coaching institute. 1 votes 1 votes Please log in or register to add a comment.
Best answer 6 votes 6 votes Using a C style creates confusion for call by name. The scope of variables comes from the function where it is called (dynamic scoping) in call by name. y++; i becomes 2 x = 5*i; a[2] becomes 10. So, 10 should be printed. Arjun answered Dec 12, 2014 • selected Jan 22, 2015 by Arjun Arjun comment Share Follow See all 0 reply Please log in or register to add a comment.
2 votes 2 votes The output printed is 1 i.e., option d). The function f() doesn't return any value neither does it make changes in the original value of a[i] and hence no matter what goes inside the body of f(), the output will be the initial value of a[i] i.e., 1. Shyam Singh answered Dec 12, 2014 Shyam Singh comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes option b . as per concept of macro implementation in c, http://www.cs.rit.edu/~rpj/courses/plc/lab4/lab47.html#Q12 sumit kumar answered Dec 11, 2014 sumit kumar comment Share Follow See all 2 Comments See all 2 2 Comments reply Shyam Singh commented Dec 12, 2014 i edited by Shyam Singh Dec 12, 2014 reply Follow Share Can you please explain how is above code snippet related to Macros in C? 0 votes 0 votes sumit kumar commented Dec 12, 2014 reply Follow Share i have given a link regarding this. macros also just substitutes the name with it's value wherever it is used in the program. call by text/name does the same . in c++ inline functions does the same by just putting the function body at every place where it is called. 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes D should be the answer. this is call by value so a[i] is unchanged. venus22 answered Dec 23, 2014 venus22 comment Share Follow See 1 comment See all 1 1 comment reply Arjun commented Dec 23, 2014 reply Follow Share In question it says call by name. 0 votes 0 votes Please log in or register to add a comment.