Call by value, call by address and call by reference in C++

Updated

The parameters of the function call are known as actual parameters and the parameters of the function definition are known as formal parameters. There are 3 ways of passing parameters in a function and they are :-

Memory boxes for call by value, call by address and call by reference, with separate cells, pointer cells and one shared cell.
  1. Call by Value
  2. Call by Address
  3. Call by Reference

1.Call by Value : In this Call by Value method, the value of the actual parameters is copied to the function’s formal parameters and different memory is allocated to the actual parameters and the function’s formal parameters. So, the changes made in the formal parameters will not be reflected in the actual parameters.

2.Call by Address: In this Call by Address method, the address of the actual parameters is passed to the function’s formal parameters and different memory is allocated to the actual parameters and the function’s formal parameters. So, the changes made in the formal parameters will also be reflected in the actual parameters.

3.Call by Reference: In this Call by Reference method, same memory address is used by both the actual parameters and the function’s formal parameters. So, the changes made in the formal parameters will also be reflected in the actual parameters.

Call by Address Call by Reference
It is also known as Call by pointer. The memory address of the actual parameters is passed to the formal parameter.

Memory is allocated for both the formal parameters and the actual parameters.

Different memory address is used by the actual parameters and the formal parameters.

C language does allow Call by Address.

It is more advisable to use.

In call by reference, the references of the actual arguments is passed to the formal parameters.

Memory is allocated to the actual parameters and formal parameters share that memory.

Same memory address is used by both the actual parameters and the function’s formal parameters.

C language doesn’t allow Call by reference.

It is less advisable to use.

// Call by Address
#include <iostream>
using namespace std;
// Here x and y are formal paramters and the pointers x and
// y will store the memory
// address of a and b and any change made in the formal
// parameters will also reflect in the actual parameters.

void swap(int* x, int* y)
{
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
    return;
}
int main()
{
    int a = 16, b = 32;
    cout << "Before Swapping a and b are " << a << " " << b
         << endl;
    // here a and b are actual parameters and we are passing
    // the address of a and b
    swap(&a, &b);
    cout << "After Swapping a and b are " << a << " " << b
         << endl;
    return 0;
}
// Call by Reference
#include <iostream>
using namespace std;
// Here x and y are formal paramters . x and a will share
// the
// memory address and y and b will share the memory address
// so any change made in the formal parameters x and y will
// also reflect in the actual parameters a and b.

void swap(int& x, int& y)
{
    int temp;
    temp = x;
    x = y;
    y = temp;
    return;
}
int main()
{

    int a = 16, b = 32;
    cout << "Before Swapping a and b are " << a << " " << b
         << endl;
    // here a and b are actual parameters and we are passing
    // it by reference
    swap(a, b);
    cout << "After Swapping a and b are " << a << " " << b
         << endl;
    return 0;
}
Output

Before Swapping a and b are 16 32
After Swapping a and b are 32 16
Comment
Mithlesh Upadhyay Published 8 Nov 2026 · 4 min read

Mithlesh Upadhyay is a Computer Science and AI expert from Madhya Pradesh with strong academic background (BE in CSE and M.Tech in AI) and over six years of experience in technical content development. He has contributed tech articles, led teams, and worked in Full Stack Development and Data Science. He founded the w3colleges.org portal for learning resources.

Related tutorials

  • Delete an element or a range from a set in C++ STL

    Delete an element from the Set by passing its value : Approach : In this method, an element is deleted by using the erase function and calling it…

    3 min read
  • Four Pillars of Object-Oriented Programming (OOPS)

    Get an overview of four pillars of object-oriented programming (OOP) and see their suitable real life examples. What is OOP? Picture a cluttered garage?️. Tools are scattered everywhere,…

    4 min read
  • What is Overriding in C++

    Write a program in C++ to depict the concept of overriding or Dynamic polymorphism. Overriding is a type of polymorphism. Polymorphism in OOP languages means to take more…

    2 min read
  • What should we use void main() or int main() ?

    There is question that what should we use void main() or int main() ? void main() { /* ... */ } Or, int main() { /* ... */…

    2 min read
  • C Comments

    Prerequisite – C Language Introduction C comments explain code and improve readability. These do not affect program execution. You can use comments in C to clarify code and describe…

    1 min read
  • C Programming Language Standard

    Prerequisite – C Language Introduction The C programming language has various versions: C89/C90, C99, C11, and C18. GATE CS 2027 Online Test Series72 tests in the real GATE…

    2 min read