Expression (computer science): Difference between revisions

Content deleted Content added
Undid revision 598639803 by 76.1.228.181 (talk): ???
Line 1:
An '''expression''' in a [[programming language]] is a combination of one or more explicit [[value (computer science)|value]]s, [[Constant (programming)|constants]], [[variable (programming)|variable]]s, [[operator (programming)|operator]]s, and [[function (programming)|function]]s that arethe interpretedprogramming language interprets (according to theits particular [[Order of operations|rules of precedence]] and of association) for a particular programming language, whichand computes andto thenproduce produces("to (returnsreturn", in a [[state (computer science)|stateful]] environment) another value. This process, likeas for [[mathematical expression]]s, is called evaluation. The returned value can be of various [[Data type|type]]s, such as numerical, string, and logical.
 
For example, <code>2+3</code> is an arithmetic and programming expression which evaluates to 5. A variable is an expression because it denotes a value in memory, so <code>y+6</code> is an expression. An example of a relational expression is <code>4≠4</code>, which evaluates to false.<ref>[https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Expressions Javascript expressions, Mozilla] Accessed July 6, 2009</ref><ref>[https://www.cs.drexel.edu/~rweaver/COURSES/ISTC-2/TOPICS/expr.html Programming in C] Accessed July 6, 2009</ref>
 
In [[C (programming language)|C]] and most C-derived languages, a call to a function with a [[Void type|void]] return type is a valid expression, of type void.<ref>
[http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf ISO/IEC 9899:1999] section 6.3.2.2, accessed August 31, 2009
</ref>
Values of type void cannot be used, so the value of such an expression is always thrown away.
 
In many programming languages a function, and hence an expression containing a function, may have [[Side effect (computer science)|side effects]]. An expression with side effects does not normally have the property of [[referential transparency (computer science)|referential transparency]]. In many languages (e.g. C++), expressions may be ended with a semicolon (<code>;</code>) to turn the expression into an expression [[Statement (programming)|statement]]. This asks the implementation to evaluate the expression for its side-effects only, and to disregard the result of the expression.
 
In many programming languages a function, and hence an expression containing a function, may have [[Side effect (computer science)|side effects]]. An expression with side effects does not normally have the property of [[referential transparency (computer science)|referential transparency]]. In many languages (e.g. C++), expressions may be ended with a semicolon (<code>;</code>) to turn the expression into an expression [[Statement (programming)|statement]]. This asks the implementation to evaluate the expression for its side-effects only, and disregard the result of the expression.
==See also==
* [[Statement (programming)]] (contrast)