Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C Function Arguments

    When calling a function in C, arguments can be passed in two ways, by calling by value and by calling by reference. This tutorial guides you about these two ways to pass parameters to a function and demonstrates them with examples.

    Type Description
    Call by Value
    • The actual parameter is passed to a function.
    • A new memory area created for the given parameters can be used only within the function.
    • The actual parameters cannot be modified here.
    Call by Reference
    • Instead of copying a variable, a memory address is passed to function as a parameter.
    • Address operator(&) is used in the parameter of the called function.
    • Changes in function reflect the change of the original variables.

    Call by Value

    Example:

    #include<stdio.h>
    
    //function declaration
    int addition(int num1, int num2);
    
    int main()
    {
        //local variable definition
        int answer;
        int num1 = 10;
        int num2 = 5;
        
        //calling a function to get addition value
        answer = addition(num1,num2);
    
        printf("The addition of two numbers is: %d\n",answer);
        return 0;
    }
    
    //function returning the addition of two numbers
    int addition(int a,int b)
    {
        return a + b;
    }

    Program Output:

    The addition of two numbers is: 15

    Call by Reference

    Example:

    #include<stdio.h>
    
    //function declaration
    int addition(int *num1, int *num2);
    
    int main()
    {
        //local variable definition
        int answer;
        int num1 = 10;
        int num2 = 5;
        
        //calling a function to get addition value
        answer = addition(&num1,&num2);
    
        printf("The addition of two numbers is: %d\n",answer);
        return 0;
    }
    
    //function returning the addition of two numbers
    int addition(int *a,int *b)
    {
        return *a + *b;
    }

    Program Output:

    The addition of two numbers is: 15


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.