Expression (computer science): Difference between revisions

Content deleted Content added
Clarification that a variable is also an expression
Correct fact about void expression (see talk page).
Line 3:
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]]. A variable is an expression because it is a pointer to a value in memory, so y+6 is an expression. An example of a programming relational expression would be 4==4 which evaluates to true.<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 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.
It is reported for the C language that a syntactically correct function call is an expression too unless the function has void return type<ref> [http://www.d.umn.edu/~gshute/C/expressions.html C expressions, Gary Shute]Accessed July 6, 2009</ref>. However, for the Java language Bill Venners reports that void return type method calls are also expressions<ref> [http://www.artima.com/objectsandjava/webuscript/ExpressionsStatements1.html Objects and Java by Bill Venners]Accessed July 6, 2009</ref>.
 
As in [[Expression (mathematics)|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{{fact|date = July 2009}}.