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.
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.
Here’s a simple function in C# as an example:
add(int x, int y) we can see
y integer variables, which are parameters.
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.
Continuing with our previous example, let’s call the
add function and pass arguments
Where, 2 and 3 are arguments
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
3 as arguments.
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.