Next: , Up: Function Definitions   [Contents][Index]


22.1.1 Function Parameter Variables

A function parameter variable is a local variable (see Local Variables) used within the function to store the value passed as an argument in a call to the function. Usually we say “function parameter” or “parameter” for short, not mentioning the fact that it’s a variable.

We declare these variables in the beginning of the function definition, in the parameter list. For example,

fib (int n)

has a parameter list with one function parameter n, which has type int.

Function parameter declarations differ from ordinary variable declarations in several ways:

If a function has no parameters, it would be most natural for the list of parameters in its definition to be empty. But that, in C, has a special meaning for historical reasons: “Do not check that calls to this function have the right number of arguments.” Thus,

int
foo ()
{
  return 5;
}

int
bar (int x)
{
  return foo (x);
}

would not report a compilation error in passing x as an argument to foo. By contrast,

int
foo (void)
{
  return 5;
}

int
bar (int x)
{
  return foo (x);
}

would report an error because foo is supposed to receive no arguments.


Next: , Up: Function Definitions   [Contents][Index]