Parameter declarations
The function declarator includes the list of parameters that can be passed to the function when it is called by another function, or by itself.
In
C++, the parameter list of a function is referred to as its signature.
The name and signature of a function uniquely identify it. As the
word itself suggests, the function signature is used by the compiler
to distinguish among the different instances of overloaded functions.
Beginning of C++ only.
An
empty argument list in a function declaration or definition indicates
a function that takes no arguments. To explicitly indicate that a
function does not take any arguments, you can declare the function
in two ways: with an empty parameter list, or with the keyword
void: int f(void);
int f();
End of C++ only.
Beginning of C only.
An empty argument
list in a function definition indicates a function that takes
no arguments. An empty argument list in a function declaration indicates
that a function may take any number or type of arguments. Thus,
int f()
{
...
}indicates that function f takes no arguments.
However, int f();simply indicates that the
number and type of parameters is not known. To explicitly indicate
that a function does not take any arguments, you should define the
function with the keyword void.
End of C only.
An ellipsis at the
end of the parameter specifications is used to specify that a function
has a variable number of parameters. The number of parameters is equal
to, or greater than, the number of parameter specifications.
int f(int, ...);
The comma
before the ellipsis is optional. In addition, a parameter declaration
is not required before the ellipsis.
At least one parameter declaration,
as well as a comma before the ellipsis, are both required in C.
Related
information
