0 0 votes Programming in C programming-in-c output + – rahul sharma 5 1.4k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 0 0 votes Yes , a=169 , b=169 is correct answer. since static scoping is sssigned to variable b , so it will retain its value through out the program. first of all the variable b is assigned a value of 12 , and just after that procedure N is called , and it made b= b+1 to value 13 , and since b is static so it will retain the value 13 throught the program. Just after this M(b) is called and the code a=a*a is called off , so 13*13= 169. so the value of a will be 169 and b =169. http://stackoverflow.com/questions/41215162/value-of-callee-and-caller-when-using-call-by-references vishwa ratna answered Dec 19, 2016 • selected Dec 19, 2016 by rahul sharma 5 vishwa ratna comment Share Follow See all 9 Comments 9 9 Comments reply rahul sharma 5 commented Dec 19, 2016 reply Follow flag But parameter are passed by reference.So when b is Passed to M,then a will be refering to b's memory address so this 169 should be updated in b's memory location?Please clarify this point. 0 0 replyShare vishwa ratna commented Dec 19, 2016 reply Follow flag The ability to pass by reference exists for two reasons: To modify the value of the function arguments To avoid make copies of an object for performance reasons Yes , 169 will be updated in b's memory location , because the variable b is static, if it had been not ststic then the case would not as former. 0 0 replyShare rahul sharma 5 commented Dec 19, 2016 reply Follow flag Then correct output should be 169,169,if this would have been in option? 0 0 replyShare vishwa ratna commented Dec 19, 2016 reply Follow flag a is being squared as a= a*a , b is just b. b value 13 is passed to a , so a becomes 13*13 =169. b value is not modified after that. 0 0 replyShare rahul sharma 5 commented Dec 19, 2016 reply Follow flag I think you are not getting my point It is mentioned that parameters are passed by reference.Now when b passed to funtion M,then a would receive it as pass by reference .Now a pointing to b.So a and b has same address as now.Any change in a should reflect in b's actual memory location.so both should be 169? 0 0 replyShare vishwa ratna commented Dec 19, 2016 reply Follow flag I am sure the value of b will remain unchanged. If x is a variable and its type is a reference type, then changing the value of x is not the same as changing the data in the object which the value of x refers to. You can check this article , at the bottom of the page they have explained in single sentence. scroll down: http://jonskeet.uk/csharp/references.html 0 0 replyShare rahul sharma 5 commented Dec 19, 2016 reply Follow flag When a parameter is passed by reference, the caller and the callee use the same variable for the parameter. If the callee modifies the parameter variable, the effect is visible to the caller's variable. http://stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value. Can some explain this please?May be i am not able to understand 0 0 replyShare vishwa ratna commented Dec 19, 2016 reply Follow flag Apology, answer should be 169 for both a and b. http://stackoverflow.com/questions/41215162/value-of-callee-and-caller-when-using-call-by-references 0 0 replyShare rahul sharma 5 commented Dec 19, 2016 reply Follow flag Np.Its a good learning:) 0 0 replyShare Please log in or register to add a comment.