Computer Science, asked by prakasha2, 1 year ago

What is the difference between Call by Reference and Call by Value?

Answers

Answered by kvnmurty
1
In procedural languages, C , C++ etc. we have some mechanisms for passing (formal) parameters to a function.

  When a function takes in a parameter and computes result and passes back as the return value, we need to use the mechanism of call by value. In this mechanism, any modification of the value of parameter inside the called function is not reflected to the calling function. ANy modifications to be done by called function can be in global data or the return value.

  When a function takes in a parameter as call by reference, the change in the parameter value itself is not reflected in the calling function.  Actually, the memory address of the variable of interest is passed to the called function. So using that address, the called function can modify the data in that memory address. This modification is useful to the calling function.


Answered by sachin156
1
In call by reference you will get the instance of a variable. After changing parameters of function, in this case your variable will change in call method. In call by value you will get the copy of the instance. And in this case changes of parameter variable will not influence on variable that was in call method
Similar questions