Difference Between Parameters and Arguments
Last Updated :
28 Mar, 2024
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.
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, 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:
Criteria | Parameters | Arguments |
---|
Definition | Variables defined in the function declaration | Actual values or variables passed to the function |
---|
Location | Part of the function declaration | Passed to the function when it is called |
---|
Role | Define the types and order of values a function can accept | Supply the values to the parameters of a function |
---|
Naming | Named identifiers used within the function | Values used to initialize the parameters in the function |
---|
Number | Determined by the function definition | Must match the number of parameters in the function |
---|
Default Values | Can have default values in some languages | Actual values can be literals, variables, or expressions |
---|
Keyword Arguments | Not natively supported | Supported in some languages, allows passing by parameter name |
---|
Implementation:
Below are examples that demonstrates the difference between parameters and arguments:
C++
#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;
}
C
#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;
}
Java
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);
}
}
C#
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}");
}
}
JavaScript
// 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}`);
Python3
# 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}")
OutputResult of adding 5 and 3 is: 8
Similar Reads
Computer Science Subjects