kota's memex

Declaring

Functions are not objects, but do have types. A function type is characterized by it's return type as well as the number and types of its parameters. The return type of a function cannot be an array type.

When you declare a function, you use the function declaration to specify the name of the function and the return type. If the declarator includes a parameter type list and a definition, the declaration of each parameter must include an identifier, except parameter list which are void.

// Function with no parameters that returns an int.
int f(void);

// Function with no parameters that returns a pointer to an int.
int *fip();

// Two functions, each returning void, and taking two ints.
void g(int i, int j);
void h(int, int);

Declaring a function without any parameters (to imply void), like function fip above is occasionally problematic. In C++ that function would instead accept any number of arguments of any type. This is also a deprecated language feature and could be removed in the future (however unlikely). It's better to just write (void).

Defining

The function definition provides the actual implementation of the function.

int max(int a, int b)
{ return a > b ? a : b; }