Parameter vs. argument

As a beginner, two terms that often cause confusion to the developers are “parameters” and “arguments”. As a Junior Engineer I was interchangeably using the terms parameter and argument. It took me a while to understand. Many of you also using these two term interchangeably.

In this article, I will try to explain the basic difference between parameter and arguments used in the function.

Parameters

In programming, a parameter is a variable or a placeholder used in a function definition. It is a placeholder for the values that the function will receive when it is being called and hence does not have a concrete value.

Example

Here’s a simple function in C# as an example:

1
2
3
4
public int add(int x, int y)
{
    return x + y;
}

In add(int x, int y) we can see x and y integer variables, which are parameters.

Arguments

Argument is the actual data or a value passed during function invocation. When you call a function, you provide the required arguments that will fill the placeholders (parameters) defined in the function. These arguments can be constants, variables, expressions, or even other function calls.

Example

Continuing with our previous example, let’s call the add function and pass arguments

1
add(2, 3);

Where, 2 and 3 are arguments

Working Example

Here is the working example develop in c# to add the two numbers. In this example, we have a function public int add(int x, int y) which has int x and int y as parameters. And the function is invoked inside main method obj.add(2, 3); which has 2 and 3 as arguments.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
using System;
					
public class Program
{
	public static void Main()
	{
		Program obj = new Program();
		var total = obj.add(2, 3);
		Console.WriteLine("Total is : "+ total);
	}
	
	public int add(int x, int y)
	{
		return x + y;
	}
}

In this article, we have understood the basic difference between parameter and argument used in the function with example. Understanding parameter and argument is also a part of understanding the fundamental concepts of programming. If you are good at fundamental of programming you will be good at your programming skill.