Pure function
In computer programming, a pure function is a function that has the following properties: # the function return values are identical for identical arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams, i.e., referential transparency), and # the function has no side effects (no mutation of non-local variables, mutable reference arguments or input/output streams).
In computer programming, a pure function is a function that has the following properties: the function return values are identical for identical arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams, i.e., referential transparency), and the function has no side effects (no mutation of non-local variables, mutable reference arguments or input/output streams). static int fact(int n) { return n std::string s = "Hello, world!"; int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int l = 0; for (int i = 0; i can be optimized such that the value of s.length() is computed only once, before the loop. Some programming languages allow for declaring a pure property to a function: In Fortran and D, the pure keyword can be used to declare a function to be just side-effect free (i.e. have just the above property 2). The compiler may be able to deduce property 1 on top of the declaration. See also: . In the GCC, the pure attribute specifies property 2, while the const attribute specifies a truly pure function with both properties. Languages offering compile-time function execution may require functions to be pure, sometimes with the addition of some other constraints. Examples include constexpr of C++ (both properties). See also: .
References
No reference rows published for this article.
Cite this article
MLA
"Pure function." encyclopegia.org, 2026, https://encyclopegia.org/wiki/pure-function. Accessed 24 November 2026.
Chicago
"Pure function." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/pure-function.
APA
encyclopegia.org. (2026). Pure function. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/pure-function
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON