Close Menu
Technotification
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Technotification
    • Home
    • News
    • How To
    • Explained
    • Facts
    • Lists
    • Programming
    • Security
    • Gaming
    Technotification
    Home › Programming › What are Different Parameter passing techniques in Programming?

    What are Different Parameter passing techniques in Programming?

    By AyushOctober 28, 2017
    Facebook Twitter Reddit LinkedIn
    parameter passing techniques

    Different Parameter passing techniques In Programming

    If you have any programming experience you might know that almost all the popular programming languages support two parameter passing techniques namely: call-by-value and call-by-reference.

    In the call-by-value technique, the actual parameters in the method call are copied to the dummy parameters in the method definition. So, whatever changes are performed on the dummy parameters, they are not reflected on the actual parameters as the changes you make are done to the copies and to the originals.

    In the call-by-reference technique, reference (address) of the actual parameters are passed to the dummy parameters in the method definition. So, whatever changes are performed on the dummy parameters, they are reflected on the actual parameters too as both references point to same memory locations containing the original values.

    To make the concept more simple, let’s consider the following code segment which demonstrates pass-by-value. This is a program for exchanging values in two variables:

    class Swapper
    {
    int a;
    int b;
    Swapper(int x, int y)
    {
    a = x;
    b = y;
    }
    void swap(int x, int y)
    {
    int temp;
    temp = x;
    x = y;
    y = temp;
    }
    }
    class SwapDemo
    {
    public static void main(String[] args)
    {
    Swapper obj = new Swapper(10, 20);
    System.out.println(“Before swapping value of a is “+obj.a+” value of b is “+obj.b);
    obj.swap(obj.a, obj.b);
    System.out.println(“After swapping value of a is “+obj.a+” value of b is “+obj.b);
    }
    }

    The output of the above programming will be:

    Before swapping value of a is 10 value of b is 20
    After swapping value of a is 10 value of b is 20

    Although values of x and y are interchanged, those changes are not reflected on a and b. Memory representation of variables is shown in below figure:

    Let’s consider the following code segment which demonstrates pass-by-reference. This is a program for exchanging values in two variables:

    class Swapper
    {
    int a;
    int b;
    Swapper(int x, int y)
    {
    a = x;
    b = y;
    }
    void swap(Swapper ref)
    {
    int temp;
    temp = ref.a;
    ref.a = ref.b;
    ref.b = temp;
    }
    }
    class SwapDemo
    {
    public static void main(String[] args)
    {
    Swapper obj = new Swapper(10, 20);
    System.out.println(“Before swapping value of a is “+obj.a+” value of b is “+obj.b);
    obj.swap(obj);
    System.out.println(“After swapping value of a is “+obj.a+” value of b is “+obj.b);
    }
    }

    The output of the above programming will be:

    Before swapping value of a is 10 value of b is 20
    After swapping value of a is 20 value of b is 10

    The changes performed inside the method swap are reflected on a and b as we have passed the reference obj into ref that is very much as using the same object within both brackets (from where it is called and to where it is) which also points to the same memory locations as obj.

    Share. Facebook Twitter LinkedIn Tumblr Reddit Telegram WhatsApp
    Ayush

    I am a Tech lover and blogger currently studying Engineering in one of the Esteemed colleges of India i love to read and write tech blogs and do professional gaming

    Related Posts

    The Best Python Libraries for Data Visualization in 2025

    April 1, 2025

    Is C++ Still Relevant in 2025 and Beyond?

    February 20, 2025

    5 Best Programming Languages for Machine Learning in 2025

    February 18, 2025

    10 Must-Have Chrome Extensions for Web Developers in 2025

    February 17, 2025

    Difference Between C, C++, C#, and Objective-C Programming

    February 16, 2025

    How to Learn Programming Faster and Smarter in 2025

    February 14, 2025
    Lists You May Like

    10 Sites to Watch Free Korean Drama [2025 Edition]

    January 2, 2025

    The Pirate Bay Proxy List in 2025 [Updated List]

    January 2, 2025

    10 Best RARBG Alternative Sites in April 2025 [Working Links]

    April 1, 2025

    10 Best Torrent Search Engine Sites (2025 Edition)

    February 12, 2025

    10 Best GTA V Roleplay Servers in 2025 (Updated List)

    January 6, 2025

    5 Best Torrent Sites for Software in 2025

    January 2, 2025

    1337x Alternatives, Proxies, and Mirror Sites in 2025

    January 2, 2025

    10 Best Torrent Sites for eBooks in 2025 [Working]

    January 2, 2025

    10 Best Anime Torrent Sites in 2025 [Working Sites]

    January 6, 2025

    Top Free Photo Editing Software For PC in 2025

    January 2, 2025
    Pages
    • About
    • Contact
    • Privacy
    • Careers
    Privacy

    Information such as the type of browser being used, its operating system, and your IP address is gathered in order to enhance your online experience.

    © 2013 - 2025 Technotification | All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.