Concept
How do functions work in programming languages?
ComputerScienceOne / Functions
"In programming languages, a function (sometimes called subroutine or procedure) can take multiple inputs and produce one output value. We’ve already seen some examples of these functions. For example, most languages provide a math library that you can use to evaluate the square root or sine of a value x . We’ve also seen some functions with multiple input values such as the “power” function that allows you to compute f ( x, y ) = x y . Finally, the main entry point to many programs is defined by a main function. More formally, a function is a sequence of instructions (code) that is packaged into a unit that can be reused. A function performs a specific task: given a number of inputs, it executes some sequence of operations (executes some code) and “returns” (outputs) a result. The output can be captured into a variable or used in an expression by whatever code invoked or “called” the function."
Related Ideas
- How do you call a function in C?ComputerScienceOne · Calling Functions
- How are functions defined and declared in modern C?ComputerScienceOne · Declaration: Prototypes
- How do C functions return values to the calling function?ComputerScienceOne · Void Functions
- What capabilities and constraints do functions have in C?ComputerScienceOne · Declaration: Prototypes
- Where does execution begin in a C program?ComputerScienceOne · The cmain() Function
- How are void functions defined in C?ComputerScienceOne · Void Functions
- What information does a C function prototype specify?ComputerScienceOne · Declaration: Prototypes
- How do functions provide a well-defined answer?Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk · Chapter 1