# Function

In mathematics, a function is defined as a relationship between defined values and one or more variables. For example, a simple math function may be:

y = 2x

In this example, the relationship of y to x is that y is twice as much as the value assigned to x. While math functions can be far more complex than this, most are simple relative to functions used in computer programming. This may be why math functions are often referred to as "expressions," while computer functions are often called "procedures" or "subroutines."

Computer functions are similar to math functions in that they may reference parameters, which are passed, or input into the function. If the example above were written as a computer function, "x" would be the input parameter and "y" would be the resulting output value. It might look something like this:

function double(x)
{
\$y = 2 * x;
return \$y;
}

The above example is a very basic function. Most functions used in computer programs include several lines of instructions and may even reference other functions. A function may also reference itself, in which case it is called a recursive function. Some functions may require no parameters, while others may require several. While it is common for functions to return variables, many functions do not return any values, but instead output data as they run.

Functions are sometimes considered the building blocks of computer programs, since they can control both small and large amounts of data. While functions can be called multiple times within a program, they only need to be declared once. Therefore, programmers often create "libraries" of functions that can referenced by one or more programs. Still, the source code of large computer programs may contain hundreds or even thousands of functions.

## Test Your Knowledge

Which of the following best describes "runtime?"

A
It is the time between when a program loads and when it quits.
0%
B
It is the length of time it takes for computer to boot.
0%
C
It is the length of time it takes a program to open.
0%
D
It is how long a computer has been running since its last restart.
0%
Correct! Incorrect!     View the Runtime definition.
More Quizzes →

## The Tech Terms Computer Dictionary

The definition of Function on this page is an original definition written by the TechTerms.com team. If you would like to reference this page or cite this definition, please use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about this definition or would like to suggest a new technical term, please contact us.