What is the difference between call by value and call by reference? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between call by value and call by reference?

26th Nov 2016, 4:57 AM
Anonyo Sanyal
Anonyo Sanyal - avatar
4 Answers
+ 6
call by value the values passed are copied in the function arguments. and the changes occur to the function arguments only. So no change is reflected in original variables. call by reference the address of the variables is passed to function. so if any change is made to the function arguments the change will reflect in original values also. so call by value is like working on photocopy of original document where no change is made to original document. call by reference us like working on original document itself. so changes are reflected there.
26th Nov 2016, 5:10 AM
Megatron
Megatron - avatar
+ 4
Call by value passes a copy of the value stored inside a variable to the function. Whatever happens, the variable itself won't be affected. However, pass by reference passes the memory in which the variable is stored to the function. In essence, it passes the variable itself. Changes to the variable inside the function affect the variable itself, as the memory in which the variable is stored is being accessed and modified.
26th Nov 2016, 5:13 AM
Varun Ramani
Varun Ramani - avatar
+ 2
In call by Value method the value is passed as an argument to function. But in call by reference method the address of the variable is passed as an argument to function. Next in call by Value method any changes made in the formal parameters will not be reflected in actual parameters. In reference method any changes made in the formal parameters will be reflected in the actual parameters (calling function). Another difference is call by Value method works on the copy of the original data. But call by reference method it works on the original data.
26th Nov 2016, 6:25 AM
joffie
joffie - avatar
0
thanks for anwsering
2nd Dec 2016, 1:04 PM
Anonyo Sanyal
Anonyo Sanyal - avatar