Relational operator
From Wikipedia, the free encyclopedia
In computer programming languages, a relational operator symbol or a relational operator name is a lexical or syntactic unit that denotes a relation, for example, equality or greater than, among two or more domains, the members of which are typically denoted by further expressions. Expressions combined by means of a relational operator symbol form what is called a relational expression or a condition.
When there is no risk of confusion, it is common to use the briefer term relational operator to refer to the corresponding symbol or name. Strictly speaking however, the relational operator is not a lexical or syntactic unit but a mathematical object that may be denoted by many different notations.
For example, in many programming languages, the relational operator symbol that tests the equality of two expressions has this form:
X == Y
Relational operators are usually written in infix notation, if supported by the programming language, which means that they appear between their operands (the two expressions being related). However, some programming languages, such as Lisp, use prefix notation, as follows:
(= X Y)
Here are some of the most common relational operators in use in programming languages:
Relational Operator | Meaning |
---|---|
== |
Equality or identity. Used to test the equivalence of two expressions or the identity of two objects. |
=== |
Variant of identity. In some languages (e.g. PHP), represents a stronger sense of equality than == . In PHP, the result of $a === $b is TRUE if $a is equal to $b , and they are of the same type[1]. |
= |
Variant of equality. (Also an assignment operator in C-like languages.) |
<> |
Inequality. (Also a file-search specifier 'operator' in Perl.) |
!= |
Variant of inequality. Used to test the equivalence of two expressions. |
/= |
Variant of inequality. This is not as common as the above operator. |
^= |
Variant of inequality. This is not as common as the above operator. (Also a bitwise XOR assignment in C-like languages.) |
> |
Greater than. Used to test if the value of the left expression is greater than that of the right expression. |
< |
Less than. Used to test if the value of the left expression is less than that of the right expression. |
>= |
Greater than or equal to. Used to test if the value of the left expression is greater than or equal to that of the right expression. |
<= |
Less than or equal to. Used to test if the value of the left expression is less than or equal to that of the right expression. |
=< |
Variant of less than or equal to. |
!> |
Not greater than. Used in SQL. |
!< |
Not less than. Used in SQL. |
[edit] Uses outside of programming
Relational operators are sometimes used in communities of technical nature instead of words.