Call by Reference and Call by Value in C-Cpp

Call by Reference and Call by Value in C-Cpp

2 min read

Functions can be invoked in two ways: Call by Value or Call by Reference. These two ways are generally differentiated by the type of values passed to them as parameters.

Call By Value:

In this parameter passing method, values of actual parameters are copied to function’s formal parameters and the two types of parameters are stored in different memory locations. So any changes made inside functions are not reflected in actual parameters of the caller. By default, C++ uses call by value to pass arguments.

#include <iostream.h>
void change(int data); 
int main()
        int data = 3; 
        cout << "Value of the data is: " << data<< endl;  
        return 0; 
void change(int data) 
data = 5;


Value of data is: 5

Call by Reference:

Both the actual and formal parameters refer to same locations, so any changes made inside the function are actually reflected in actual parameters of caller.

Bade Kaam ki baat (BKKB): To understand the call by reference, you must have the basic knowledge of pointers.

Let’s try to understand the concept of call by reference in C++ language by the example given below:

using namespace std;
void swap(int *x, int *y) 
   int swap; 
int main() 
   int x=500, y=100; 
   swap(&x, &y);   // passing value to function 
   cout<<"Value of x is: "<<x<<endl; 
   cout<<"Value of y is: "<<y<<endl;
   return 0; 


Value of x is:100
Value of y is:500


Difference between call by value and call by reference
ParametersCall by ValueCall by Reference
BasicA copy of the variable is passed.A variable itself is passed.
effectChange in a cop of variable doesn’t modify the original value of variable.Change in a copy of variable modify the original value of variable.
Default CallingPrimitive types are passed using “call_by_value”.Objects are implicitly passed using “call_by_reference”.

If you liked my article please follow me on @priya123 to get the latest articles and post by me.

Choose your Reaction!
  • Wonderful blog! Do you have any helpful hints for aspiring writers? I’m hoping to start my own blog soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m completely confused .. Any recommendations? Many thanks!

    • Comment Hii okon, thanks for your response. I think it totally depends on you, whether you want to do writing for free or want it to be paid. In any of the way you can improve your skills.

Leave a Comment