The difference between an argument and a parameter

The difference between an argument and a parameter

The terms "argument" and "parameter" are often used interchangeably to describe function input variables and the values that are given to them, although they are definitely related, they do not describe the exact same thing.


The terms "argument" and "parameter" are often used interchangeably to describe function specific input variables and the values that are given to them, and although they are definitely related, they do not refer the exact same thing.


Function input variables are used to pass certain values into a function when it is called within your code, these values can affect the outcome of the execution of the function and control exactly what is does.


A parameter is the actual function specific variable that you would use inside your function, this is the variable that is declared within your parameter list and can only be used within the scope of that function.


void functionName( parameter1, parameter2 ){    
    return ( parameter1 + parameter2 );    
}    

In this pseudo-code example we declare two parameters, these are then only used within the scope of the function.


An argument is the actual value that is passed to the function when it is called, the argument is assigned to the parameter upon execution.


functionName( argument1, argument2 );


As an example, let's' create the function "test" which will include 2 parameters, and call it while providing 2 arguments.


The difference between function parameters and arguments


The parameters- param1 and param2- are assigned the arguments- 5 and 6. The parameters are now equal to the given arguments when the function executes.



Christopher Thornton@Instructobit 6 years ago
or