Function (computer programming)

In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed.
— Wikipedia

So functions is sort of group of instruction to perform some elementary task. We can execute function anytime by calling it.

In different programming languages, a function may be called a routine, subprogram, subroutine, method, or procedure.

Usually function consist of these parts:

  • Declaration: name, parameters (arguments) and return type
  • Definition: body of function (content), this is what executed when function called (or invoked).
  • Return value: function result (one or many)

A function call may also have ==side effects== such as modifying data structures in a computer memory, reading from or writing to a peripheral device, creating a file, halting the program or the machine, or even delaying the program’s execution for a specified time.

              ----------
Arguments -> | Function | -> Side effects
              ----------