A definition is a self-contained block of code with a specific purpose.


Definitions are frequently split into header code, which contains information relevant to the user of the code (e.g. a subroutine header contains its identifier and parameters that are used when the subroutine is called), and body code, or the body, which contains the statements used to execute the code.

A definition is often referred to as a function definition if it defines a function. In a function definition, the header is immediately followed by the body of the function.

header

Header code identifies the entity to which it relates.

The function's header defines what the function is and its return type.

A function header consists of three parts:

A function header usually takes the following form:

type identifier( parameters )

where

type is the type of the variable returned by the function .
identifier is the identifier by which the function can be called.
parameters is the function's parameter list .
body

Body code consists of a sequence of statements. These statements are executed when the entity to which the code relates (e.g. function) is invoked.

The function's body contains the executable code for the function. This forms the actual executable part of the function.

In may langages, including C++, the function body is enclosed between braces {}.

Sometimes header and body code are included in a program's code at one location while another copy of the header code is included somewhere else, often in a file containing only header code and thus referred to as a header file, which has a filename extension of .h. This second copy of the header can be referred to as a prototype. It is included for reference by dependent code and can be used as a declaration. In many languages a function must be declared before it can be used. If the header and body are declared elsewhere in the code, the declaration is effected using a prototype.

A prototype is a statement that specifies the function's return type, identifier and parameters. The prototype contains the same information as appears in the function header. Because the prototype is a statement, many languages require it to terminate with a semicolon ;.

The number of parameters and their types must be the same in the function prototype as they are in the function header in the definition of the function. In most languages prototypes for functions used in a program must appear before the statements calling the functions.


example Java
home Home Page