When verbally talking about methods, I\'m never sure whether to use the word argument or parameter or something else. Either way the other people know what
Parameter is variable in the declaration of function.
Argument is the actual value of this variable that gets passed to function.
Let's say you're an airline. You build an airplane. You install seats in it. Then, you fill the plane up with passengers and send it somewhere. The passengers (or rather, some spatio-temporally altered version thereof) disembark. Next day, you re-use the same plane, and same seats, but with different passengers this time.
The plane is your function.
The parameters are the seats.
The arguments are the passengers that go in those seats.
According to Joseph's Alabahari book "C# in a Nutshell" (C# 7.0, p. 49) :
static void Foo (int x)
{
x = x + 1; // When you're talking in context of this method x is parameter
Console.WriteLine (x);
}
static void Main()
{
Foo (8); // an argument of 8.
// When you're talking from the outer scope point of view
}
In some human languages (afaik Italian, Russian) synonyms are widely used for these terms.
In my university professors use both kind of names.
This example might help.
int main () {
int x = 5;
int y = 4;
sum(x, y); // **x and y are arguments**
}
int sum(int one, int two) { // **one and two are parameters**
return one + two;
}
A "parameter" is a very general, broad thing, but an "argument: is a very specific, concrete thing. This is best illustrated via everyday examples:
Most machines take an input and return an output. For example a vending machine takes as an input: money, and returns: fizzy drinks as the output. In that particular case, it accepts as a parameter: money.
What then is the argument? Well if I put $2.00 into the machine, then the argument is: $2.00 - it is the very specific input used.
Let's consider a car: they accept petrol (unleaded gasoline) as an input. It can be said that these machines accept parameters of type: petrol. The argument would be the exact and concrete input I put into my car. e.g. In my case, the argument would be: 40 litres of unleaded petrol/gasoline.
An argument is a particular and specific example of an input. Suppose my machine takes a person as an input and turns them into someone who isn't a liar.
What then is an argument? The argument will be the particular person who is actually put into the machine. e.g. if Colin Powell is put into the machine then the argument would be Colin Powell.
So the parameter would be a person as an abstract concept, but the argument would always be a particular person with a particular name who is put into the machine. The argument is specific and concrete.
That's the difference. Simple.
Post a comment and I'll fix up the explanation.
They both dont have much difference in usage in C, both the terms are used in practice. Mostly arguments are often used with functions. The value passed with the function calling statement is called the argument, And the parameter would be the variable which copies the value in the function definition (called as formal parameter).
int main ()
{
/* local variable definition */
int a = 100;
int b = 200;
int ret;
/* calling a function to get max value */
ret = max(a, b);
printf( "Max value is : %d\n", ret );
return 0;
}
/* function returning the max between two numbers */
int max(int num1, int num2)
{
/* local variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
In the above code num1
and num2
are formal parameters and a
and b
are actual arguments.