Functions specify the logical structure of a program, and define how operations are implemented.
A function declaration consists of a return type, a name, and an argument list. It is used to declare the format and existence of a function prior to its use.
A function definition contains a function declaration, and the body of the function. A function can have only one definition.
C functions can be declared or defined in two ways:
| prototyped | Type information is provided with each parameter. The compiler uses the function prototype for argument type checking and argument conversions. Prototypes can appear several times in a program, provided the declarations are compatible. They allow the compiler to check for mismatches between the parameters of a function call and those in the function declaration. |
| nonprototyped | No type information is provided in the function declaration. Type information for each parameter in a function definition is provided after a list of parameters. |
Prototypes are the preferred style of function declaration. The ANSI C standard has declared the nonprototyped style obsolete.
C++
functions must use prototypes. They are usually placed in header
files, while function definitions appear in source files.
![]()
Function Calls
Arithmetic
Conversions
Integral Promotions
Standard Type
Conversions
Function Specifiers
![]()
main()
Function
Function
Declarations
Function
Definitions
return
Statement
Arithmetic
Conversions