Open In App

Difference Between Parameters and Arguments

Parameters refer to the variables listed in a function's declaration, defining the input that the function can accept. Arguments, however, are the actual values passed to the function when it is called, filling the parameters during execution.

Parameters:

In programming, a parameter is a variable in a function or method declaration. It serves as a placeholder for data that will be provided when the function or method is called. Parameters define the type and number of values that a function or method can accept.

They define the types and order of values that a function can accept. Parameters are used to receive the arguments passed to a function when it is called.

Example:

def add(x, y):  # Here, x and y are parameters
return x + y

Arguments:

Arguments, also known as actual arguments, are the values supplied to a function when it is called. These values serve as inputs to the function during its execution.

They are used to supply the values to the parameters of a function. The number of arguments must match the number of parameters in the function definition.

Example:

result = add(5, 3)  # Here, 5 and 3 are arguments

Difference Between Parameters and Arguments:

Below is a table summarizing the difference between arguments and parameters:

CriteriaParametersArguments
DefinitionVariables defined in the function declarationActual values or variables passed to the function
LocationPart of the function declarationPassed to the function when it is called
RoleDefine the types and order of values a function can acceptSupply the values to the parameters of a function
NamingNamed identifiers used within the functionValues used to initialize the parameters in the function
NumberDetermined by the function definitionMust match the number of parameters in the function
Default ValuesCan have default values in some languagesActual values can be literals, variables, or expressions
Keyword ArgumentsNot natively supportedSupported in some languages, allows passing by parameter name

Implementation:

Below are examples that demonstrates the difference between parameters and arguments:

#include <iostream>

// Function definition with parameters
int add(int x, int y) {  // x and y are parameters
    return x + y;
}

int main() {
    // Calling the function with arguments
    int result = add(5, 3);  // 5 and 3 are arguments
    
    // Display the result
    std::cout << "Result of adding 5 and 3 is: " << result << std::endl;
    
    return 0;
}
#include <stdio.h>

// Function definition with parameters
int add(int x, int y)
{
    // x and y are parameters
    return x + y;
}

int main()
{
    // Calling the function with arguments
    // 5 and 3 are arguments
    int result = add(5, 3);

    // Display the result
    printf("Result of adding 5 and 3 is: %d\n", result);

    return 0;
}
public class Main {
    // Function definition with parameters
    public static int add(int x, int y) {  // x and y are parameters
        return x + y;
    }

    public static void main(String[] args) {
        // Calling the function with arguments
        int result = add(5, 3);  // 5 and 3 are arguments
        
        // Display the result
        System.out.println("Result of adding 5 and 3 is: " + result);
    }
}
using System;

public class Program {
    // Function definition with parameters
    public static int Add(int x, int y) {  // x and y are parameters
        return x + y;
    }

    public static void Main() {
        // Calling the function with arguments
        int result = Add(5, 3);  // 5 and 3 are arguments
        
        // Display the result
        Console.WriteLine($"Result of adding 5 and 3 is: {result}");
    }
}
// Function definition with parameters
function add(x, y) {  // x and y are parameters
    return x + y;
}

// Calling the function with arguments
let result = add(5, 3);  // 5 and 3 are arguments

// Display the result
console.log(`Result of adding 5 and 3 is: ${result}`);
# Function definition with parameters
def add(x, y):  # x and y are parameters
    return x + y

# Calling the function with arguments
result = add(5, 3)  # 5 and 3 are arguments

# Display the result
print(f"Result of adding 5 and 3 is: {result}")

Output
Result of adding 5 and 3 is: 8
Article Tags :