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

0 like 0 dislike
asked May 12, 2018 in General by Tarunjaiswal (100 points)

When using Call by Value, you are sending the value of a variable as parameter to a function, whereas Call by Reference sends the address of the variable. Also, under Call by Value, the value in the parameter is not affected by whatever operation that takes place, while in the case of Call by Reference, values can be affected by the process within the function.

1 Answer

0 like 0 dislike
answered May 22, 2018 by MayankSingh (33 points)
call by valuecall by reference

In call by value, a copy of actual arguments is passed to formal arguments of the called function and any change made to the formal arguments in the called function have no effect on the values of actual arguments in the calling function.

In call by reference, the location (address) of actual arguments is passed to formal arguments of the called function. This means by accessing the addresses of actual arguments we can alter them within from the called function.

In call by value, actual arguments will remain safe, they cannot be modified accidentally.

In call by reference, alteration to actual arguments is possible within from called function; therefore the code must handle arguments carefully else you get unexpected results.

Make sure your Question & Answer should be appropriate and useful to the reader. Don't just copy and paste content from other sources.