Give an example of when passing parameters by value as opposed to passing them by reference is a better technique. Now give an example of when passing parameters by reference as opposed to passing them by value is a better technique. For each example explain why you believe that technique is better than the other.© BrainMass Inc. brainmass.com October 9, 2019, 11:34 pm ad1c9bdddf
Pass by Value
A parameter passed by value is just that - the caller passes a value to the procedure. Pass by value parameters are input only parameters. That is, you can pass them to a procedure but the procedure cannot return values through them.
If we don't want changes made within a function on parameters passed to a function to affect other parts of the program then "pass by value" method is the better technique over "pass by reference"
let's take a look at the following code example:
//include this file for cout
// square a number and return it
double square(double value)
value = value * ...
The expert provides an example when passing parameters by value as opposed to passing them by reference is a better technique.