parameter computer programming in computer programming a parameter or a formal argument is a special kind of variable used in a subroutine to refer to one of the pieces of data provided as input to the subroutine of the arguments often called actual arguments or actual parameters with which the subroutine is going to be calledinvoked an ordered list of parameters is usually included in the definition of a subroutine so that each time the subroutine is called its arguments for that call are evaluated and the resulting values can be assigned to the corresponding parameters unlike argument in usual mathematical usage the argument in computer science is thus the actual input expression passedsupplied to a function procedure or routine in the invocationcall statement whereas the parameter is the variable inside the implementation of the subroutine for example if one defines the add subroutine as def addx y return x y then x y are parameters while if this is called as add2 3 then 2 3 are the arguments note that variables and expressions thereof from the calling context can be arguments if the subroutine is called as a 2 b 3 adda b then the variables a b are the arguments not the values 2 3 see the parameters and arguments section for more information in the most common case call by value a parameter acts within the subroutine as a new local variable initialized to the value of the argument a local isolated copy of the argument if the argument is a variable but in other cases eg call by reference the argument variable supplied by the caller can be affected by actions within the called subroutine as discussed in evaluation strategy the semantics for how parameters can be declared and how the value of arguments are passed to the parameters of subroutines are defined by the language but the details of how this is represented in any particular computer system depend on the calling conventions of that system example the following program in the c programming language defines a function that is named salestax and has one parameter named price the type of price is double ie a doubleprecision floating point number the functions return type is also a double double salestaxdouble price return 005 price after the function has been defined it can be invoked as follows salestax1000 in this example the function has been invoked with the argument 1000 when this happens 1000 will be assigned to price and the function begins calculating its result the steps for producing the result are specified below enclosed in 005 price indicates that the first thing to do is multiply 005 by the value of price which gives 050 return means the function will produce the result of 005 price therefore the final result ignoring possible roundoff errors one encounters with representing decimal fractions in ieee754 format is 050 parameters and arguments the terms parameter and argument may have different meanings in different programming languages sometimes they are used interchangeably and the context is used to distinguish the meaning the term parameter sometimes called formal parameter is often used to refer to the variable as found in the function definition while argument sometimes called actual parameter refers to the actual input supplied at function call for example if one defines a function as def fx then x is the parameter and if it is called by a fa then a is the argument a parameter is an unbound variable while the argument can be a value or variable or more complex expression involving values and variables in case of call by value what is passed to the function is the value of the argument for example f2 and a 2 fa are equivalent calls while in call by reference with a variable as argument what is passed is a reference to that variable even though the syntax for the function call could stay the same the specification for passbyreference or passbyvalue would be made in the function declaration andor definition parameters appear in procedure definitions arguments appear in procedure calls in the function definition fx xx the variable x is a parameter in the function call f2 the value 2 is the argument of the function loosely a parameter is a type and an argument is an instance a parameter is an intrinsic property of the procedure included in its definition for example in many languages a procedure to add two supplied integers together and calculate the sum would need two parameters one for each integer in general a procedure may be defined with any number of parameters or no parameters at all if a procedure has parameters the part of its definition that specifies the parameters is called its parameter list by contrast the arguments are the expressions supplied to the procedure when it is called usually one expression matching one of the parameters unlike the parameters which form an unchanging part of the procedures definition the arguments may vary from call to call each time a procedure is called the part of the procedure call that specifies the arguments is called the argument list although parameters are also commonly referred to as arguments arguments are sometimes thought of as the actual values or references assigned to the parameter variables when the subroutine is called at runtime when discussing code that is calling into a subroutine any values or references passed into the subroutine are the arguments and the place in the code where these values or references are given is the parameter list when discussing the code inside the subroutine definition the variables in the subroutines parameter list are the parameters while the values of the parameters at runtime are the arguments for example in c when dealing with threads its common to pass in an argument of type void and cast it to an expected type void threadfunction void pthreadargument naming the first parameter pthreadargument is correct rather than pthreadparameter at run time the value we use is an argument as mentioned above reserve the term parameter for when discussing subroutine definitions to better understand the difference consider the following function written in c int sumint addend1 int addend2 return addend1 addend2 the function sum has two parameters named addend1 and addend2 it adds the values passed into the parameters and returns the result to the subroutines caller using a technique automatically supplied by the c compiler the code which calls the sum function might look like this int sumvalue int value1 40 int value2 2 sumvalue sumvalue1 value2 the variables value1 and value2 are initialized with values value1 and value2 are both arguments to the sum function in this context at runtime the values assigned to these variables are passed to the function sum as arguments in the sum function the parameters addend1 and addend2 are evaluated yielding the arguments 40 and 2 respectively the values of the arguments are added and the result is returned to the caller where it is assigned to the variable sumvalue because of the difference between parameters and arguments it is possible to supply inappropriate arguments to a procedure the call may supply too many or too few arguments one or more of the arguments may be a wrong type or arguments may be supplied in the wrong order any of these situations causes a mismatch between the parameter and argument lists and the procedure will often return an unintended answer or generate a runtime error alternative convention in eiffel within the eiffel software development method and language the terms argument and parameter have distinct uses established by convention the term argument is used exclusively in reference to a routines inputs consider the following routine definition sum addend1 integer addend2 integer integer do result addend1 addend2 end the routine sum takes two arguments addend1 and addend2 which are called the routines formal arguments a call to sum specifies actual arguments as shown below with value1 and value2 sumvalue integer value1 integer 40 value2 integer 2 sumvalue sum value1 value2 parameters are also thought of as either formal or actual formal generic parameters are used in the definition of generic classes in the example below the class hashtable is declared as a generic class which has two formal generic parameters g representing data of interest and k representing the hash key for the data class hashtable when a class becomes a client to hashtable the formal generic parameters are substituted with actual generic parameters in a generic derivation in the following attribute declaration mydictionary is to be used as a character string based dictionary as such both data and key formal generic parameters are substituted with actual generic parameters of type string mydictionary hashtable datatypes in strongly typed programming languages each parameters type must be specified in the procedure declaration languages using type inference attempt to discover the types automatically from the functions body and usage dynamically typed programming languages defer type resolution until runtime weakly typed languages perform little to no type resolution relying instead on the programmer for correctness some languages use a special keyword eg void to indicate that the subroutine has no parameters in formal type theory such functions take an empty parameter list whose type is not void but rather unit argument passing the exact mechanism for assigning arguments to parameters called argument passing depends upon the evaluation strategy used for that parameter typically call by value which may be specified using keywords default arguments some programming languages such as ada c clojure common lisp fortran 90 python ruby tcl and windows powershell allow for a default argument to be explicitly or implicitly given in a subroutines declaration this allows the caller to omit that argument when calling the subroutine if the default argument is explicitly given then that value is used if it is not provided by the caller if the default argument is implicit sometimes by using a keyword such as optional then the language provides a wellknown value such as null empty zero an empty string etc if a value is not provided by the caller powershell example function docg 121 g gigawatts g gigawatts great scott ps doc 121 gigawatts 121 gigawatts great scott ps doc 88 88 gigawatts 88 gigawatts great scott default arguments can be seen as a special case of the variablelength argument list variablelength parameter lists some languages allow subroutines to be defined to accept a variable number of arguments for such languages the subroutines must iterate through the list of arguments powershell example function marty args foreach back to the year ps marty 1985 back to the year 1985 ps marty 2015 1985 1955 back to the year 2015 back to the year 1985 back to the year 1955 named parameters some programming languagessuch as ada and windows powershellallow subroutines to have named parameters this allows the calling code to be more selfdocumenting it also provides more flexibility to the caller often allowing the order of the arguments to be changed or for arguments to be omitted as needed powershell example function jenniferadjectiveyoung adjectiveold young jennifer im adjectiveyoung old jennifer im adjectiveold ps jennifer fresh experienced young jennifer im fresh old jennifer im experienced ps jennifer adjectiveold experienced adjectiveyoung fresh young jennifer im fresh old jennifer im experienced multiple parameters in functional languages in lambda calculus each function has exactly one parameter what is thought of as functions with multiple parameters is usually represented in lambda calculus as a function which takes the first argument and returns a function which takes the rest of the arguments this is a transformation known as currying some programming languages like ml and haskell follow this scheme in these languages every function has exactly one parameter and what may look like the definition of a function of multiple parameters is actually syntactic sugar for the definition of a function that returns a function etc function application is leftassociative in these languages as well as in lambda calculus so what looks like an application of a function to multiple arguments is correctly evaluated as the function applied to the first argument then the resulting function applied to the second argument etc output parameters an output parameter also known as an out parameter or return parameter is a parameter used for output rather than the more usual use for input using call by reference parameters or call by value parameters where the value is a reference as output parameters is an idiom in some languages notably c and c and the scripting language tscript see tscript function declarations more precisely one may distinguish three types of parameters or parameter modes input parameters output parameters and inputoutput parameters these are often denoted in out and in out or inout an input argument the argument to an input parameter must be a value such as an initialized variable or literal and must not be redefined or assigned to an output argument must be an assignable variable but it need not be initialized any existing value is not accessible and must be assigned a value and an inputoutput argument must be an initialized assignable variable and can optionally be assigned a value the exact requirements and enforcement vary between languages for example in ada 83 output parameters can only be assigned to not read even after assignment this was removed in ada 95 to remove the need for an auxiliary accumulator variable these are analogous to the notion of a value in an expression being an rvalue has a value an lvalue can be assigned or an rvaluelvalue has a value and can be assigned respectively though these terms have specialized meanings in c in some cases only input and inputoutput are distinguished with output being considered a specific use of inputoutput and in other cases only input and output but not inputoutput are supported the default mode varies between languages in fortran 90 inputoutput is default while in c and sql extensions input is default and in tscript each parameter is explicitly specified as input or output syntactically parameter mode is generally indicated with a keyword in the function declaration such as void fout int x in c conventionally output parameters are often put at the end of the parameter list to clearly distinguish them though this is not always followed tscript uses a different approach where in the function declaration input parameters are listed then output parameters separated by a colon and there is no return type to the function itself as in this function which computes the size of a text fragment textextentwstring text font font integer width integer height parameter modes are a form of denotational semantics stating the programmers intent and allowing compilers to catch errors and apply optimizations they do not necessarily imply operational semantics how the parameter passing actually occurs notably while input parameters can be implemented by call by value and output and inputoutput parameters by call by reference and this is a straightforward way to implement these modes in languages without builtin support this is not always how they are implemented this distinction is discussed in detail in the ada 83 rationale which emphasizes that the parameter mode is abstracted from which parameter passing mechanism by reference or by copy is actually implemented a syntactically similar construction to output parameters is to assign the return value to a variable with the same name as the function this is found in pascal and fortran 66 and fortran 77 as in this pascal example function fx y integer integer begin f x y end this is semantically different in that when called the function is simply evaluated it is not passed a variable from the calling scope to store the output in use the primary use of output parameters is to return multiple values from a function while the use of inputoutput parameters is to modify state using parameter passing rather than by shared environment as in global variables an important use of returning multiple values is to solve the semipredicate problem of returning both a value and an error status see semipredicate problem multivalued return for example to return two variables from a function in c one may write int width height fx width height where x is an input parameter and width and height are output parameters passed by reference a common use case in c and related languages is for exception handling where a function places the return value in an output variable and returns a boolean corresponding to whether the function succeeded or not an archetypal example is the tryparse method in net especially c which parses a string into an integer returning true on success and false on failure this has the following signature public static bool tryparsestring s out int result and may be used as follows int result if int32tryparses result exception handling similar considerations apply to returning a value of one of several possible types where the return value can specify the type and then value is stored in one of several output variables another use is as a microoptimization to avoid assigning a local variable in a function and then needing to copy it when returning this can be done when output parameters are implemented by call by reference for example in c instead of the more usual largeobject obj fx one might instead write largeobject obj fx obj so the function f does not need to assign space for the object or copy it on returning drawbacks output parameters are often discouraged in modern programming essentially as being awkward confusing and too lowlevel commonplace return values are considerably easier to understand and work with notably output parameters involve functions with side effects modifying the output parameter and are semantically similar to references which are more confusing than pure functions and values and the distinction between output parameters and inputoutput parameters can be subtle further since in common programming styles most parameters are simply input parameters output parameters and inputoutput parameters are unusual and hence susceptible to misunderstanding output and inputoutput parameters prevent function composition since the output is stored in variables rather than in the value of an expression thus one must initially declare a variable and then each step of a chain of functions must be a separate statement for example in c the following function composition object obj gy fx when written with output and inputoutput parameters instead becomes for f it is an output parameter for g an inputoutput parameter object obj fx obj gy obj in the special case of a function with a single output or inputoutput parameter and no return value function composition is possible if the output or inputoutput parameter or in cc its address is also returned by the function in which case the above becomes object obj gy fx obj alternatives there are various alternatives to the use cases of output parameters for returning multiple values from a function an alternative is to return a tuple syntactically this is clearer if automatic sequence unpacking and parallel assignment can be used as in go or python such as def f return 1 2 a b f for returning a value of one of several types a tagged union can be used instead the most common cases are nullable types option types where the return value can be null to indicate failure for exception handling one can return a nullable type or raise an exception for example in python one might have either result parses if result is none exception handling or more idiomatically try result parses except parseerror exception handling the microoptimization of not requiring a local variable and copying the return when using output variables can also be applied to conventional functions and return values by sufficiently sophisticated compilers the usual alternative to output parameters in c and related languages is to return a single data structure containing all return values for example given a structure encapsulating width and height one can write widthheight widthandheight fx in objectoriented languages instead of using inputoutput parameters one can often use call by sharing passing a reference to an object and then mutating the object though not changing which object the variable refers to commandline argument evaluation strategy operator overloading free variables and bound variables notes 