Definition of Parameters

Parameters are components of functions

Format
mla apa chicago
Your Citation
Bolton, David. "Definition of Parameters." ThoughtCo, Feb. 18, 2017, thoughtco.com/definition-of-parameters-958124. Bolton, David. (2017, February 18). Definition of Parameters. Retrieved from https://www.thoughtco.com/definition-of-parameters-958124 Bolton, David. "Definition of Parameters." ThoughtCo. https://www.thoughtco.com/definition-of-parameters-958124 (accessed October 18, 2017).

Parameters identify values that are passed into a function. For example, a function to add three numbers might have three parameters. A function has a name, and it can be called from other points of a program. When that happens, the information passed is called an argument. Modern programming languages typically allow functions to have several parameters.

Function Parameters

Each function parameter has a type followed by an identifier, and each parameter is separated from the next parameter by a comma.

The parameters pass arguments to the function. When a program calls a function, all the parameters are variables. The value of each of the resulting arguments is copied into its matching parameter in a process call pass by value. The program uses parameters and returned values to create functions that take data as input, make a calculation with it and return the value to the caller.

The Difference Between Functions and Arguments

The terms parameter and argument are sometimes used interchangeably. However, parameter refers to the type and identifier, and arguments are the values passed to the function. In the following C++ example, int a and int b are parameters, while 5 and 3 are the arguments passed to the function.

int addition (int a, int b)
{
  int r;
  r=a+b;
  return r;
}

int main ()
{
  int z;
  z = addition (5,3);
  cout << "The result is " << z;
}

Value of Using Parameters

  • Parameters allow a function to perform tasks without knowing the specific input values ahead of time.
  • Parameters are indispensable components of functions, which programmers use to divide their code into logical blocks.
Format
mla apa chicago
Your Citation
Bolton, David. "Definition of Parameters." ThoughtCo, Feb. 18, 2017, thoughtco.com/definition-of-parameters-958124. Bolton, David. (2017, February 18). Definition of Parameters. Retrieved from https://www.thoughtco.com/definition-of-parameters-958124 Bolton, David. "Definition of Parameters." ThoughtCo. https://www.thoughtco.com/definition-of-parameters-958124 (accessed October 18, 2017).