Difference Between Call by Reference and Call by Value

Functions can be invoked in two ways in a program. One method is by call by reference, and the next method is by call by value. These methods can be differentiated based on the type of values that are passed to the parameters.


IT Quiz

Test your knowledge about topics related to technology

1 / 10

Which American Computer Company is also known by the nick name "Big Blue"

2 / 10

Which of the following semiconductor is mostly used to construct electronic circuits?

3 / 10

The output printed by a computer through a printer on the paper is called

4 / 10

What is Artificial Intelligence?

5 / 10

LED stands for:

6 / 10

Who is considered as the father of computing

7 / 10

When a machine possesses the ability to mimic human traits like make decisions, predict the future, learn and improve on its own said to have

8 / 10

Everyone knows what a robot is, but what is a 'cobot'?

9 / 10

Which number system has a base 16

10 / 10

The main function of smart assistants like Apple Siri and Amazon Alexa is

Your score is


The parameters that are used in them are called actual parameters. They are used in many programming languages like C, C++, and Java.

Call by Reference vs Call by Value

The difference between Call by Reference and Call by Value is that in the call by reference, a variable itself will be passed. On the other hand, in the call by reference, a copy of the variable will be passed. Programming languages are only supported and stored as default in the call by reference method. Whereas in the call by value method, the programming languages are default.

Call by Reference vs Call by Value

Want to save this article for later? Click the heart in the bottom right corner to save to your own articles box!

Call by reference method is used for accessing the actual argument that is the function call. This means that changes are made in the parameter only after the argument is passed.

It uses the same memory allocation that is used in actual parameters. When it calls a function, instead of copying the variables, the address itself is used in the call by references.

Call by value is a subroutine that passes the actual data of the parameters that are used in the subroutine.

In this method, when you call a function, you are passing the value to the variable of the arguments in the called function so that the called function works on the value. This change will not be reflected in the called function.

Comparison Table

Parameters of ComparisonCall by ReferenceCall by Value
VariableVariable is passed.Copy of the variable is passed.
Variable valueChanges made will affect the function outside.Changes made will not affect the function outside.
Original valueIt is modified.It is not modified.
SafetyActual arguments are not safe.Actual arguments are safe.
DefinitionIt uses a variable itself for passing.It uses the copy of the variable for passing.

What is Call by Reference?

It is a method used for passing arguments to a function. To store the address of the variables, pointer variables are used. In this method, actual arguments are not safe.

Accidental modifications can be made. It is important to handle the argument operations carefully. It helps to avoid changes made by mistake.

It will not create any duplicate data as it holds only one value so that it can save memory space. If a person reads the code, they won’t be able to find whether the values are modified in this code are not.

In this method, a lifetime guarantee is a big issue. It will become a danger if you work with multi-threaded programs and lambdas. To declare call by reference, you should pass an address.

Call by reference when it comes to C programming. It directly accesses the data items and performs the functions on them. But you must be careful as pointers are involved in it.

If you know the particular status of the data item, then call by reference method id perfect. Modifying a copy of the data is not going to do anything useful

Call by reference has dangers that call by value does not. You can inadvertently reassign a value to a pointer and lose it in memory.

What is Call by Value?

In this method, changes made inside the function of the parameter will not have any effect on the argument. Swap program acts as the best example of call by value program.

It explains that no changes are made in the value even though they are changed inside the function. In java, the call by value method means calling the method with its parameter as a value.

In this method, the parameters are stored in different memory locations. If you make any change inside the location actual parameter of the caller will not be affected.

This method is best because the original value is not modified. But you cannot make any changes to the actual variables. Actual arguments will be safe in this method as you cannot make any changes accidentally. 

This method preserves the data as it does not change the original variable. Here arguments are variables. Changing a variable in a function body is not direct. Complex expressions can work as arguments sometimes.

It is not memory efficient as two copies are created for the same variable. If the data size is large, the call-by-value method will not address them. In that case, programmers should go for the call by reference method. 

Main Differences Between Call by Reference and Call by Value

  1. The original value is modified in the call by reference. On the other hand, in the call by value original value is not modified.
  2. Call by reference is supported by programming languages, but it does not default. On the other hand, call by value works default in programming languages.
  3. In Call by reference, any changes made in the variable will also affect the variable outside the function. On the other hand, in the call by value, any changes made in the variable will not affect the variable outside the function.
  4. Call by reference allows you to make changes in the variable value. On the other hand, call-by-value will not allow you to make changes.
  5. In call by reference, an address of the value will be passed. But in the call by reference, a copy of the value will be passed. 
  1. https://www.jstor.org/stable/3857812
  2. ftp://prog.vub.ac.be/education/EMOOSE/ReuseSlides/merge-papers/Jackson&al1994-semanticDiff.pdf
One request?

I’ve put so much effort writing this blog post to provide value to you. It’ll be very helpful for me, if you consider sharing it on social media or with your friends/family. SHARING IS ♥️

Leave a Comment

Your email address will not be published. Required fields are marked *