Function

Why Trust Techopedia

What Does Function Mean?

A function is a unit of code that is often defined by its role within a greater code structure. Specifically, a function contains a unit of code that works on various inputs, many of which are variables, and produces concrete results involving changes to variable values or actual operations based on the inputs.

Advertisements

Techopedia Explains Function

Within a greater code structure, a function, which also may be called a subroutine or procedure, is “called” by the code, depending on a user event or as part of a greater operation. When called, the function operates on the inputs and produces the results.

A basic example is a function called “addone” that will take a variable x, which is defined as an integer, and add one. The code within addone would look something like this:

input “x”
x = x + 1
output “x”

An example of a function that operates on inputs instead may look like this:

input “x”
if x > 5 then
print x
end

Here, the function may or may not print, depending on the value of “x.”

Advertisements

Related Terms

Margaret Rouse
Technology expert
Margaret Rouse
Technology expert

Margaret is an award-winning writer and educator known for her ability to explain complex technical topics to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles in the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret’s idea of ​​a fun day is to help IT and business professionals to learn to speak each other’s highly specialized languages.