Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arguments or parameters? [duplicate]

People also ask

What is difference between arguments and parameters?

Note the difference between parameters and arguments: Function parameters are the names listed in the function's definition. Function arguments are the real values passed to the function. Parameters are initialized to the values of the arguments supplied.

What are arguments and parameters in C++?

The values that are declared within a function when the function is called are known as an argument. The variables that are defined when the function is declared are known as parameters. 2. These are used in function call statements to send value from the calling function to the receiving function.

What is the difference between an argument and a parameter in Python?

The terms parameter and argument can be used for the same thing: information that are passed into a function. From a function's perspective: A parameter is the variable listed inside the parentheses in the function definition. An argument is the value that are sent to the function when it is called.


Parameters are the things defined by functions as input, arguments are the things passed as parameters.

void foo(int bar) { ... }

foo(baz);

In this example, bar is a parameter for foo. baz is an argument passed to foo.


A Parameter is a variable in the declaration of a function:

functionName(parameter) {
    // do something
}


An Argument is the actual value of this variable that gets passed to the function:

functionName(argument);

For user1515422, a very concrete example showing the difference between parameters and arguments:

Consider this function:

int divide(int numerator, int denominator) {
    return numerator/denominator;
}

It has two parameters: numerator and denominator, set when it's defined. Once defined, the parameters of a function are fixed and won't change.

Now consider an invocation of that function:

int result = divide(8, 4);

In this case, 8 and 4 are the arguments passed to the function. The numerator parameter is set to the value of the argument 8, and denominator is set to 4. Then the function is evaluated with the parameters set to the value of the arguments. You can think of the process as equivalent to:

int divide() {
    int numerator = 8;
    int denominator = 4;
    return numerator/denominator;
}

The difference between a parameter and an argument is akin to the difference between a variable and its value. If I write int x = 5;, the variable is x and the value is 5. Confusion can arise because it's natural to say things like "x is five," as shorthand for "The variable x has the value 5," but hopefully the distinction is clear.

Does that clarify things?


Arguments are what you have when you're invoking a subroutine. Parameters are what you are accessing inside the subroutine.

argle(foo, bar);

foo and bar are arguments.

public static void main(final String[] args) {
    args.length;
}

args is a parameter.