An expression in a programming language is a combination of values, variables, operators, and functions that are interpreted (evaluated) according to the particular rules of precedence and of association for a particular programming language, which computes and then produces (returns, in a stateful environment) another value. The expression is said to evaluate to that value[citation needed].
For example 2+3 is an arithmetic and programming expression which evaluates to 5. The assignment expression x=2+3 also evaluates to 5 and is a programming expression, but is an equation in mathematics and not a mathematical expression. An example of a programming relational expression would be 4==4 which evaluates to true.[1][2]
It is reported for the C language that a syntactically correct function call is an expression too unless the function has void return type[3]. However, for the Java language Bill Venners reports that void return type method calls are also expressions[4].
As in math, the expression is (or can be said to have) its evaluated value; the expression is a representation of that value. So, in mathematics, an expression is a representation of a value[citation needed].
Expressions may or may not have side effects. An expression with side effects does not normally have the property of referential transparency. In many languages (e.g. C++) statements may be ended with a semicolon ';' to turn the expression into an expression statement. This asks the implementation to evaluate the expression for its side-effects only, and disregard the result of the expression[citation needed].
See also
References
- ^ Javascript expressions, MozillaAccessed July 6, 2009
- ^ Programming in CAccessed July 6, 2009
- ^ C expressions, Gary ShuteAccessed July 6, 2009
- ^ Objects and Java by Bill VennersAccessed July 6, 2009
External links
- This article is based on material taken from Expression at the Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of the GFDL, version 1.3 or later.