Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

The decision of whether to pass a parameter by reference or by value in C++ depends

on several factors, including the size of the data, the need for modification, and
performance considerations. But my personal opinion is the decision should be based
off of the following:

We should pass by value when:


- Parameter Value not Needed:
When the function does not need to modify the parameter, and the value remains
unchanged.

We should pass by reference when:


- Parameter Value Modification Needed:
When the function needs to modify the original value of the parameter. Pass by
reference allows changes to the original data.

In summary:
- If you don't want to change the value of the argument you're passing through a
function we pass by VALUE.
- If you want to change the value of the argument you're passing through a function
we pass by REFERENCE.

It's also important to note that this can completely depend on how the logic behind
your function works, it's up to you to code the logic behind your functions
and make your functions work as you intended them to.

You might also like