Difference between Call by Value and Call by Reference - Shikshaglobe

Content Creator: Vijay Kumar

The distinction between Call by Value and Call by Reference


What is Call by Value technique?

Call by esteem strategy duplicates the worth of contention into the conventional boundary of that capability. Thusly, changes made to the boundary of the principal capability don't influence the contention.

"Call by value" and "call by reference" are two different methods used in programming languages to pass arguments to functions or procedures. These methods dictate how data is transferred between the calling code and the called function. Here's a detailed explanation of the differences between call by value and call by reference:

Click here to explore

Call by Value:

1.     Argument Passing:

·         In call by value, a copy of the actual data (the value) is passed to the function. The function operates on this copy, leaving the original data unchanged.

2.     Data Protection:

·         Call by value protects the original data from being modified within the function. Any changes made to the data inside the function do not affect the data outside the function.

3.     Example:

·         If you pass a variable x with the value 5 to a function using call by value, the function will receive a copy of 5. Any changes made to this copy, such as setting it to 10, will not affect the original x, which remains 5.

4.     Usage:

·         Call by value is commonly used when you want to ensure that the original data remains unchanged and that the function cannot inadvertently modify it.

Your gateway to success

Call by Reference:

1.     Argument Passing:

·         In call by reference, a reference or memory address of the original data is passed to the function. This means the function operates directly on the original data.

2.     Data Modification:

·         Call by reference allows functions to modify the original data. Any changes made to the data inside the function are reflected in the original data outside the function.

3.     Example:

·         If you pass a variable x with the value 5 to a function using call by reference, the function will receive a reference to the memory location of x. Any changes made to this reference, such as setting it to 10, will directly affect the original x, changing it to 10.

Get started today

4.     Usage:

·         Call by reference is used when you want a function to have the capability to modify the original data or when you need to pass large data structures efficiently without copying them.

Key Differences:

  • Data Copying: Call by value involves copying the data, while call by reference passes a reference to the original data.
  • Data Protection: Call by value protects the original data from modification by the function, whereas call by reference allows the function to modify the original data.
  • Efficiency: Call by value can be less efficient for large data structures since it involves data copying. Call by reference is more efficient in such cases.
  • Complexity: Call by value is conceptually simpler, as the function works with a copy of the data. Call by reference can introduce complexity due to the potential for unintended side effects on the original data.
  • Use Cases: Call by value is often used when data integrity is critical, while call by reference is used when you want a function to modify data directly or when you need to pass large data structures efficiently.

In this boundary passing technique, the upsides of genuine boundaries are replicated to work's conventional boundaries, and the boundaries are put away in various memory areas. So any progressions made inside capabilities are not reflected in that frame of mind of the guest.


What is Call by Reference technique?

Call by reference strategy duplicates the location of contention into the proper boundary. In this strategy, the location is utilized to get to the genuine contention utilized in the capability call. It implies that changes made in the boundary modify the passing contention.


In this technique, the memory designation is equivalent to the real boundaries. All the activities in the capability are performed on the worth put away at the location of the real boundary, and the adjusted worth will be put away at a similar location.

Take the next step

Benefits of utilizing Call by esteem strategy

Masters/advantages of a call by esteem technique:


The technique doesn't change the first factor, so it is safeguarding information.

Whenever a capability is called it, never influence the real items in the genuine contentions.

The worth of genuine contentions passed to the conventional contentions, so any progressions posted in the proper viewpoint don't influence the genuine cases.


Benefits of utilizing Call by reference strategy

Geniuses of utilizing call by reference technique:

The capability can change the worth of the contention, which is very valuable.

It doesn't make copy information for holding just a single worth which assists you with saving memory space.

In this strategy, there is no duplicate of the contention made. In this manner, it is handled exceptionally quickly.

Assists you with staying away from changes done unintentionally

An individual perusing the code never realizes that the worth can be changed in the capability.


Hindrances of utilizing Call by esteem strategy

Here, are significant cons/disadvantages of a call by esteem strategy:

Changes to genuine boundaries can likewise alter comparing contention factors

In this technique, contentions should be factors.

You can't straightforwardly change a variable in a capability body.

At some point, contention can be mind-boggling articulations

There are two duplicates made for a similar variable which isn't memory effective.

Hindrances of utilizing Call by reference strategy

Here, are significant cons of utilizing call by reference technique:


Solid non-invalid assurance. A capability taking in a reference needs to ensure that the info is non-invalid. Subsequently, an invalid check need not be made.

Passing by reference makes the capability not unadulterated hypothetically.

A lifetime ensure is a major issue with references. This is explicitly hazardous while working with lambdas and multi-string programs.


Read More Information:

Featured Universities

Mahatma Gandhi University

Location: Soreng ,Sikkim , India
Approved: UGC
Course Offered: UG and PG

MATS University

Location: Raipur, Chhattisgarh, India
Approved: UGC
Course Offered: UG and PG

Kalinga University

Location: Raipur, Chhattisgarh,India
Approved: UGC
Course Offered: UG and PG

Vinayaka Missions Sikkim University

Location: Gangtok, Sikkim, India
Approved: UGC
Course Offered: UG and PG

Sabarmati University

Location: Ahmedabad, Gujarat, India
Approved: UGC
Course Offered: UG and PG

Arni University

Location: Tanda, Himachal Pradesh, India.
Approved: UGC
Course Offered: UG and PG

Capital University

Location: Jhumri Telaiya Jharkhand,India
Approved: UGC
Course Offered: UG and PG

Glocal University

Location: Saharanpur, UP, India.
Approved: UGC
Course Offered: UG and PG

Himalayan Garhwal University

Location: PG, Uttarakhand, India
Approved: UGC
Course Offered: UG and PG

Sikkim Professional University

Location: Sikkim, India
Approved: UGC
Course Offered: UG and PG

North East Frontier Technical University

Location: Aalo, AP ,India
Approved: UGC
Course Offered: UG and PG