Function

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

Latest Programming Languages Terms

Related Reading

Margaret Rouse

Margaret Rouse is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical, business audience. Over the past twenty years her explanations have appeared on TechTarget websites and she's been cited as an authority in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine and Discovery Magazine.Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages. If you have a suggestion for a new definition or how to improve a technical explanation, please email Margaret or contact her…