Jump to content

Function (programming)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Michael Hardy (talk | contribs) at 23:54, 17 March 2003. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In programming, a function is a part of a program that can be called with certain arguments (or parameters) from inside the program or elsewhere, and returns a value.

Although the term is related to the mathematical term it is less strict; a function may return different results each time, even if it is called with the same arguments, and a function may have side-effects, that is, it may cause changes that remain after the call of the function has ended. Such functions can be mathematically modelled by incorporating a notion of time and global parameters: see denotational semantics for a fuller treatment of this subject.

An exception to this difference is a function in pure functional programming that returns always the same result if called with the same arguments and has no side effects.

A procedure is similar to a function but has only side effects and does not return a value. In some programming languages, such as ANSI C, where there are only functions there is often a type such as void for the result of a function that has no result.