FACTOID # 61: The average woman in New Zealand doesn't give birth until she is nearly 30 years old.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS   

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Parameter (computer science)

In computer programming, a parameter is a variable which takes on the meaning of a corresponding argument passed in a call to a subroutine. In the most common case, call-by-value, a parameter acts within the subroutine as a local (isolated) copy of the argument, but in other cases, e.g. call-by-reference, the argument supplied by the caller can be affected by actions within the called subroutine (as discussed in evaluation strategy). “Programming” redirects here. ... In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and can be relatively independent of the remaining code. ... Parameters are a way of allowing the same sequence of commands to operate on different data without re-specifying the instructions. ... In computer science, a local variable is a variable that is given local scope. ... Parameters are a way of allowing the same sequence of commands to operate on different data without re-specifying the instructions. ... In computer science, an evaluation strategy is a set of (usually deterministic) rules for determining the evaluation of expressions in a programming language. ...


Nearly all programming languages support subroutine parameters. The semantics for how parameters can be declared and how the arguments get passed to the parameters of subroutines are defined by the language, but the details of how this is represented in any particular computer system depends on the calling conventions of that system. Other listings of programming languages are: Categorical list of programming languages Generational list of programming languages Chronological list of programming languages Note: Esoteric programming languages have been moved to the separate List of esoteric programming languages. ... To meet Wikipedias quality standards, this article or section may require cleanup. ...

Contents

Parameters and arguments

Although parameters are also commonly referred to as arguments, arguments are more properly 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 subroutine's parameter list are the parameters, while the values of the parameters at runtime are the arguments. Parameters are a way of allowing the same sequence of commands to operate on different data without re-specifying the instructions. ... In computer science, runtime or run time describes the operation of a computer program, the duration of its execution, from beginning to termination (compare compile time). ...


Many programmers use parameter and argument interchangeably, depending on context to distinguish the meaning. In practice, distinguishing between the two terms is usually unnecessary in order to use them correctly or communicate their use to other programmers. Alternatively, the equivalent terms formal parameter and actual parameter may be used.


To better understand the difference, consider the following subroutine written in C: C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...

 int sum(int addend1, int addend2) { return addend1 + addend2; } 

The subroutine sum has two parameters, named addend1 and addend2. It adds the values passed into the parameters, and returns the result to the subroutine's caller (using a technique automatically supplied by the C compiler).


The code which calls the sum subroutine might look like this:

 int sumValue; int value1 = 40; int value2 = 2; sumValue = sum(value1, value2); 

The variables value1 and value2 are initialized with values. The variables are not arguments or parameters.


At runtime, the values assigned to these variables are passed to the subroutine sum. In the sum subroutine, 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.


Datatypes

In strongly-typed programming languages that are explicitly typed, each parameter's type is specified in the subroutine's declaration. Languages using type inference attempt to discover the types automatically from the function's body and usage, while weakly-typed programming languages defer type resolution to run-time. In computer science and computer programming, the term strong typing is used to describe those situations where programming languages specify one or more restrictions on how operations involving values having different datatypes can be intermixed. ... In computer science, a datatype or data type (often simply a type) is a name or label for a set of values and some operations which one can perform on that set of values. ... Type inference is a feature present in some strongly statically typed programming languages. ...


Some languages use a special keyword (e.g. 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). At the broadest level, type theory is the branch of mathematics and logic that first creates a hierarchy of types, then assigns each mathematical (and possibly other) entity to a type. ... A unit type is a mathematical type that allows only one value. ...


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. In computer science, an evaluation strategy is a set of (usually deterministic) rules for determining the evaluation of expressions in a programming language. ...


Default arguments

Some programming languages such as Windows PowerShell and Python allow for a default argument to be explicitly or implicity given in a subroutine's 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 well-known value (such as null, Empty, zero, an empty string, etc.) if a value is not provided by the caller. Windows PowerShell, previously Microsoft Shell or MSH (codenamed Monad) is an extensible command line interface (CLI) shell and scripting language product developed by Microsoft. ... Python is a high-level programming language first released by Guido van Rossum in 1991. ... In computer programming, a default argument is an argument to a function that a programmer is not required to specify. ... In computer programming, null is a special value for a pointer (or other kind of reference) used to signify that the pointer intentionally does not have a target. ...


PowerShell example:

 function doc($g = 1.21) { "$g gigawatts? $g gigawatts? Great Scott!" } 
 PS> doc 1.21 gigawatts? 1.21 gigawatts? Great Scott! 
 PS> doc 88 88 gigawatts? 88 gigawatts? Great Scott! 

Variable-length 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. In computer programming, a variadic function is a function of variable arity; that is, one which can take different numbers 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 languages allow subroutines to have named parameters. This allows the calling code to be more self-documenting. 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. To meet Wikipedias quality standards, this article or section may require cleanup. ... In computer science, self-documenting refers to the ability of a piece of code or something else to require users have little or no previous knowledge of its specification, purpose and behavior to use it effectively. ...


PowerShell example:

 function jennifer($young, $old) { "Young Jennifer: I'm $young!" "Old Jennifer: I'm $old!" } 
 PS> jennifer 'old' 'young' Young Jennifer: I'm old! Old Jennifer: I'm young! 
 PS> jennifer -old 'young' -young 'old' Young Jennifer: I'm old! Old Jennifer: I'm young! 

See also


  Results from FactBites:
 
Parameter - Wikipedia, the free encyclopedia (1552 words)
Strictly speaking, parameters are denoted by the symbols that are part of the function's definition, while arguments are the values that are supplied to the function when it is used.
For example, Spearman is a non-parametric test as it is computed from the order of the data regardless of the actual values, whereas Pearson is a parametric test as it is computed directly from the data and can be used to derive a mathematical relationship.
When the terms formal parameter and actual parameter are used, they generally correspond with the definitions used in computer science.
  More results at FactBites »

 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your location
Your comments
Please enter the 5-letter protection code


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.