Difference between the Call by Value and Call by Reference in C++

The major difference between the two methods of passing the parameters is given below:

Feature

Call by Value

Call by Reference

Value Passed In this method, the value of the variable is passed to the function. In call by reference memory address of the variable is passed.
Scope of Changes In this method, the original value remains unchanged even when we make changes in the function. In this method, the changes made are reflected in the original variable.
Performance It may require extra memory and time to copy so less efficient. It is more memory and time efficient as compared to “call by value”.
Memory Location The memory addresses of the actual and formal parameters are different. The actual and the formal parameters point at the same memory address.
Applications Mainly used to pass values for small data or when we do not want to change original values. It is used when we want to modify the original value or save resources.

Difference Between Call by Value and Call by Reference in C++

In C++ programming we have different ways to pass arguments to functions mainly by Call by Value and Call by Reference method. These two methods differ by the types of values passed through them as parameters.

Before we look into the call-by-value and call-by-reference methods, we first need to know what are actual and formal parameters.

The actual parameters also known as arguments are the parameters that are passed into the function when we make a function call whereas formal parameters are the parameters that we see in the function or method definition i.e. the parameters received by the function.

Similar Reads

Call by Value in C++

In the call-by-value method, function arguments are passed by copying the value of the actual parameter, ensuring the original values remain unchanged. The value is copied to the formal parameter....

Call by Reference in C++

...

Difference between the Call by Value and Call by Reference in C++

In the call-by-reference method, the memory address (reference) of the actual parameter is passed to the function, allowing direct access and modification of the original values. The actual and the formal parameters point to the same memory address. Any changes made to the parameters within the function are directly reflected in the original values outside the function....

Conclusion

...