Operator (computer programming): Difference between revisions

Content deleted Content added
Dexbot (talk | contribs)
m WP:CHECKWIKI error fix. Section heading problem. Violates WP:MOSHEAD.
Reverting vandalism.
Tag: nowiki added
Line 1:
{{refimprove|date=January 2012}}
[[Category:Operators (programming)| ]]
[[Category:Programming constructs]]
An operator, in Java, is a special symbols performing specific operations on one, two or three operands and then returning a result. The operators are classified and listed according to precedence order. Java operators are generally used to manipulate primitive data types. The Java operators are classified into eight different categories:Arithmetic, Incement and Decrement, Relational, Logical, Conditional, Assignment, Bitwise and Miscellaneous Operators.
 
[[Programming languages]] typically support a set of '''operators''': constructs which behave generally like functions, but which differ syntactically or semantically from usual functions. Common simple examples include arithmetic (addition with <code>+</code>), comparison (with <code>&gt;</code>), and logical operations (such as <code>AND</code> or <code>&amp;&amp;</code>). More involved examples include assignment (usually <code>=</code> or <code>:=</code>), [[Field (computer science)|field]] access in a record or object (usually <code>.</code>), and the [[scope resolution operator]] (often <code>::</code>). Languages usually define a set of built-in operators, and in some cases allow user-defined operators.
== Types of Opreators: ==
 
==Syntax==
'''''(i).Arithmetic Operators: / * % + -'''''
[[Syntax (programming languages)|Syntactically]] operators usually contrast to [[Function (computer science)|functions]]. In most languages, functions may be seen as a special form of prefix operator with fixed [[Order of operations|precedence]] level and associativity, often with compulsory [[Bracket#Parentheses .28 .29|parentheses]] e.g. <code>Func(a)</code> (or <code>(Func a)</code> in [[Lisp (programming language)|LISP]]). Most languages support programmer-defined functions, but cannot really claim to support programmer-defined operators, unless they have more than prefix notation and more than a single precedence level. Semantically operators can be seen as special form of function with different calling notation and a limited number of parameters (usually 1 or 2).
 
The position of the operator with respect to its operands may be [[Polish notation|prefix]], [[infix notation|infix]] or [[postfix notation|postfix]], and the syntax of an [[expression (computer science)|expression]] involving an operator depends on its [[arity]] (number of [[operand]]s), precedence, and (if applicable), [[Operator associativity|associativity]]. Most programming languages support [[binary operation|binary operators]] and a few [[unary operation|unary operators]], with a few supporting more operands, such as the [[?:]] operator in C, which is ternary. There are prefix unary operators, such as unary minus <code>-x</code>, and postfix unary operators, such as [[post-increment]] <code>x++</code>; and binary operations are infix, such as <code>x + y</code> or <code>x = y</code>. Infix operations of higher arity require additional symbols, such as the [[ternary operator]] ?: in C, written as <code>a ? b : c</code> – indeed, this is the only common example, it is often referred to as ''the'' ternary operator. Prefix and postfix operations can support any desired arity, however, such as <code>1 2 3 4 +</code>.
'''''(ii).Increment and Decrement Operators: ++ --'''''
 
Occasionally<ref>[http://reference.wolfram.com/mathematica/tutorial/OperatorInputForms.html#11350 Mathematica reference]</ref><ref>[http://maxima.sourceforge.net/docs/manual/en/maxima_7.html#SEC36 Maxima reference]</ref> parts of a language may be described as "matchfix" or "circumfix"<ref>[http://mythryl.org/my-Prefix__Postfix_and_Circumfix_Operators.html Prefix, Postfix and Circumfix Operators in Mythryl]</ref><ref>[http://doc.perl6.org/language/operators#___top Common Perl 6 infixes, prefixes, postfixes, and more!]</ref> operators, either to simplify the language's description or implementation. A circumfix operator consists of two or more parts which enclose its operands. Circumfix operators have the highest precedence, with their contents being evaluated and the resulting value used in the surrounding expression. The most familiar circumfix operator are the parentheses mentioned above, used to indicate which parts of an expression are to be evaluated before others. Another example from physics is the [[Inner product space|inner product]] notation of Dirac's [[bra–ket notation]]. Circumfix operators are especially useful to denote operations that involve many or varying numbers of operands.
'''''(iii).Relational Operators: < <= > >= == != += -= ~= &='''''
 
The specification of a language will specify the syntax the operators it supports, while languages such as [[Prolog]] that support programmer-defined operators require that the syntax be defined by the programmer.
'''''(iv).Logical Operators: ! && ||'''''
 
==Semantics==
'''''(v).Conditional Operators: ? :'''''
The semantics of operators particularly depends on value, evaluation strategy, and argument passing mode (such as boolean short-circuiting). Simply, an [[Expression (computer science)|expression]] involving an operator is evaluated in some way, and the resulting [[Value (computer science)|value]] may be just a value (an r-value), or may be an object allowing assignment (an l-value).
 
In simple cases this is identical to usual function calls; for example, addition <code>x + y</code> is generally equivalent to a function call <code>add(x, y)</code> and less-than comparison <code>x &lt; y</code> to <code>lt(x, y)</code>, meaning that the arguments are evaluated in their usual way, then some function is evaluated and the result is returned as a value. However, the semantics can be significantly different. For example, in assignment <code>a = b</code> the target <code>a</code> is not evaluated, but instead its ''___location'' (address) is used to store the value of <code>b</code> – corresponding to [[call-by-reference]] semantics. Further, an assignment may be a statement (no value), or may be an expression (value), with the value itself either an r-value (just a value) or an l-value (able to be assigned to). As another example, the [[scope resolution operator]] :: and the element access operator . (as in <code>Foo::Bar</code> or <code>a.b</code>) operate not on values, but on ''names'', essentially [[call-by-name]] semantics, and their value is a name.
'''''(vi).Assignment Operators: = /= /* %= *= **= <<= >>= >>>= ^= |='''''
 
Use of l-values as operator operands is particularly notable in unary [[increment and decrement operators]]. In C, for instance, the following statement is legal and well-defined, and depends on the fact that array indexing returns an l-value:
'''''(vii). Bitwise Operators: ~ & | ^ << >> >>>'''''
<source lang=c>
x = ++a[i];
</source>
 
An important use is when a left-associative binary operator modifies its left argument (or produces a side effect) and then evaluates to that argument as an l-value.{{efn|Conversely a right-associative operator with its right argument, though this is rarer.}} This allows a sequence of operators all affecting the original argument, allowing a [[fluent interface]], similar to [[method cascading]]. A common example is the <code>&lt;&lt;</code> operator in the C++ <code>[[iostream]]</code> library, which allows fluent output, as follows:
'''''(viii). Miscellaneous Operators: . new () [] (type)'''''
<source lang=cpp>
cout << "Hello" << " " << "world!" << endl;
</source>
 
==User-defined operators==
== Arithmetic Operators: ==
A language may contain a fixed number of built-in operators (e.g. {{mono|1=+, -, *, &lt;, &lt;=, !, =}}, etc. in [[Operators in C and C++|C and C++]], [[PHP]]), or it may allow the creation of programmer-defined operators (e.g. [[F Sharp (programming language)|F#]], [[OCaml]], [[Haskell programming language|Haskell]]). Some programming languages restrict operator symbols to special characters like {{mono|1='''[[Addition|+]]'''}} or {{mono|1='''[[Assignment (computer science)|:=]]'''}} while others allow also names like <code>[[Integer_division#Division_of_integers|'''div''']]</code> (e.g. [[Pascal (programming language)|Pascal]]).
An arithmetic operator is a mathematical function that takes two operands and performs a calculation on them. They are used in common arithmetic and most computer languages contain a set of such operators that can be used within equations to perform a number of types of sequential calculation. Basic arithmetic operators include:
 
Most languages have a built-in set of operators, but do not allow user-defined operators, as this significantly complicates parsing.{{efn|Introducing a new operator changes the [[lexical specification]] of the language, which changes the [[lexical analysis]]. The arity and precedence of the operator is then part of the phrase syntax of the language, which changes the phrase-level analysis. For example, adding an operator <code>@</code> requires lexing and tokenizing this character, and the phrase structure (syntax tree) depends on the arity and precedence of this operator.}} Many languages only allow operators to be used for built-in types, but others allow existing operators to be used for user-defined types; this is known as [[operator overloading]]. Some languages allow new operators to be defined, however, either at compile time or at run time. This may involve meta-programming (specifying the operators in a separate language), or within the language itself. Definition of new operators, particularly runtime definition, often makes correct [[static analysis]] of programs impossible, since the syntax of the language may be Turing-complete, so even constructing the syntax tree may require solving the halting problem, which is impossible. This occurs for [[Perl]], for example, and some dialects of [[Lisp (programming language)|Lisp]].
{| class="wikitable"
|+
!Operator
!Meaning
!Use
!
|-
|/
|Divide
|For division
|
|-
|*
|Multiply
|For Multiplication
|
|-
|%
+
 
==Examples==
-
{{category see also|Operators (programming)}}
|Modulo
Common examples that differ syntactically are mathematical [[arithmetic operation]]s, e.g. "&gt;" for "[[inequality (mathematics)|greater than]]", with names often outside the language's set of [[identifier (computer science)|identifiers]] for functions, and called with a syntax different from the language's syntax for calling functions. As a function, "greater than" would generally be named by an identifier, such as <code>gt</code> or <code>greater_than</code> and called as a function, as <code>gt(x, y)</code>. Instead, the operation uses the special character <code>&gt;</code> (which is tokenized separately during [[lexical analysis]]), and infix notation, as <code>x &gt; y</code>.
Plus
 
Common examples that differ semantically (by argument passing mode) are boolean operations, which frequently feature [[short-circuit evaluation]]: e.g. a short-circuiting conjunction (X AND Y) that only evaluates later arguments if earlier ones are not false, in a language with strict call-by-value functions. This behaves instead similarly to if/then/else.
Minus
|For finding the remainder
For addition
 
Less common operators include:
For Subtraction
* [[Comma operator]]: <code>e, f</code>
|
* [[Dereference operator]]: <code>*p</code> and address-of operator: <code>&amp;x</code>
|}
* [[?:]] or ternary operator: <code>number = spell_out_numbers ? "forty-two" : 42</code>
** [[Elvis operator]]: <code>x ?: y</code>
* [[Null coalescing operator]]: <code>x ?? y</code>
* [[Spaceship operator]] (for [[three-way comparison]]): <code>x &lt;=&gt; y</code>
 
==Compilation==
== Increment and Decrement Operators: ==
A compiler can implement operators and functions with [[Subroutine|subroutine calls]] or with [[Inline expansion|inline code]]. Some built-in operators supported by a language have a direct mapping to a small number of [[Machine code|instructions]] commonly found on [[central processing units]], though others (''e.g.'' '+' used to express [[string concatenation]]) may have complicated implementations.
'''Increment''' and '''decrement operators''' are unary operators that ''add'' or ''subtract'' one from their operand, respectively. They are commonly implemented in imperative programming languages. C-like languages feature two versions (pre- and post-) of each operator with slightly different semantics.
 
== Operator overloading ==
In languages syntactically derived from B (including C and its various derivatives), the increment operator is written as <code>++</code> and the decrement operator is written as <code>--</code>.
{{main|Operator overloading}}
 
In some programming languages an operator may be ''ad-hoc polymorphic'', that is, have definitions for more than one kind of data, (such as in [[Java (programming language)|Java]] where the <tt>+</tt> operator is used both for the addition of numbers and for the concatenation of strings). Such an operator is said to be ''overloaded''. In languages that support operator overloading by the programmer (such as [[C++]]) but have a limited set of operators, operator overloading is often used to define customized uses for operators.
== Relational Operators ==
In computer science, a '''relational operator''' is a programming language construct or operator that tests or defines some kind of relationbetween two entities. These include numerical equality (''e.g.'', 5 = 5) and inequalities (''e.g.'', 4 ≥ 3).
 
In the example <code>IF ORDER_DATE > "12/31/2011" AND ORDER_DATE < "01/01/2013" THEN CONTINUE ELSE STOP</code>, the operators are: ">" (greater than), "AND" and "<" (less than).
{| class="wikitable"
|+
!Operator
!Meaning
!
!
|-
|<
<=
 
>
|Smaller than
Smaller than equal to
 
Sreater than
|
|
|-
|>=
<nowiki>= =</nowiki>
 
<nowiki>!=</nowiki>
|Greater than equal to
Equal to
 
not equal to
|
|
|-
| -=
~=
 
&=
|?!?!?!?!?!?!?!?!?!?!?!
|
|
|}
 
== Logical Operators ==
The Logical operators are:
 
; '''<code>op1 && op2</code>'''
: -- Performs a logical AND of the two operands.
; '''<code>op1</code> || <code>op2</code>'''
: -- Performs a logical OR of the two operands.
; '''<code>!op1</code>'''
: -- Performs a logical NOT of the operand.
 
The concept of logical operators is simple. They allow a program to make a decision based on multiple conditions. Each operand is considered a condition that can be evaluated to a true or false value. Then the value of the conditions is used to determine the overall value of the <code>op1 operator op2</code> or <code>!op1</code> grouping. The following examples demonstrate different ways that logical conditions can be used.
 
== Conditional Operators: ==
The conditional operator (? :) is a ternary operator (it takes three operands). The conditional operator works as follows:
 
>The first operand is implicitly converted to bool. It is evaluated and all side effects are completed before continuing.
 
>If the first operand evaluates to true (1), the second operand is evaluated.
 
>If the first operand evaluates to false (0), the third operand is evaluated.
 
The result of the conditional operator is the result of whichever operand is evaluated — the second or the third. Only one of the last two operands is evaluated in a conditional expression.
 
Conditional expressions have right-to-left associativity. The first operand must be of integral or pointer type. The following rules apply to the second and third operands:
 
>If both operands are of the same type, the result is of that type.
 
>If both operands are of arithmetic or enumeration types, the usual arithmetic conversions (covered in Arithmetic Conversions) are performed to convert them to a common type. If both operands are of pointer types or if one is a pointer type and the other is a constant expression that evaluates to 0, pointer conversions are performed to convert them to a common type. If both operands are of reference types, reference conversions are performed to convert them to a common type.
 
>If both operands are of type void, the common type is type void.
 
>If both operands are of the same user-defined type, the common type is that type.
 
== Operand coercion ==
>If the operands have different types and at least one of the operands has user-defined type then the language rules are used to determine the common type. (See warning below.)
{{further|Type conversion}}
Some languages also allow for the operands of an operator to be implicitly converted, or ''[[Type conversion#Implicit type conversion|coerced]]'', to suitable data types for the operation to occur. For example, in [[Perl]] coercion rules lead into <code>12 + "3.14"</code> producing the result of <code>15.14</code>. The text <code>"3.14"</code> is converted to the number 3.14 before addition can take place. Further, <code>12</code> is an integer and <code>3.14</code> is either a floating or fixed-point number (a number that has a decimal place in it) so the integer is then converted to a floating point or fixed-point number respectively.
 
[[JavaScript]] follows opposite rules—finding the same expression above, it will convert the integer <code>12</code> into a string <code>"12"</code>, then concatenate the two operands to form <code>"123.14"</code>.
Any combinations of second and third operands not in the preceding list are illegal. The type of the result is the common type, and it is an l-value if both the second and third operands are of the same type and both are l-values.
 
In the presence of coercions in a language, the programmer must be aware of the specific rules regarding operand types and the operation result type to avoid subtle programming mistakes.
== Assignment Operators: ==
An '''assignment operator''' assigns a value to its left operand based on the value of its right operand.
 
== Operator features in programming languages ==
The basic assignment operator is equal (<code>=</code>), which assigns the value of its right operand to its left operand. That is, <code>x = y</code> assigns the value of <code>y</code> to <code>x</code>. The other assignment operators are usually shorthand for standard operations, as shown in the following definitions and examples.
The following table shows the operator features in several programming languages:
 
{| class="sortable wikitable"
!Name
!Shorthand operator
!Meaning
|-
!Programming language
|Assignment
!Nonalphanumeric operator symbols
|<code>x = y</code>
!Alphanumeric operator symbols
|<code>x = y</code>
!Prefix
!Infix
!Postfix
!Precedence
!Associativity
!Overloading
!Programmer-defined overloading
!Programmer-defined operator symbols
|-
| [[ALGOL 68]]
|Addition assignment
| {{mono|1=+* ** * / % %* %× - + &lt; &lt;= >= > = /= & -:= +:= *:= /:= %:= %*:= +=: :=: :/=:}}
|<code>x += y</code>
(All operators have '''bold''' Alphanumeric equivalents, c.f. next column. Some have non [[ASCII]] equivalents, c.f. below.)
|<code>x = x + y</code>
{{mono|1=¬ +× ⊥ ↑ ↓ ⌊ ⌈ × ÷ ÷× ÷* □ ≤ ≥ ≠ ∧ ∨ ×:= ÷:= ÷×:= ÷*:= %×:= :≠:}}
| {{mono|'''not''' '''abs''' '''arg''' '''bin''' '''entier''' '''leng''' '''level''' '''odd''' '''repr''' '''round''' '''shorten''' '''i''' '''shl''' '''shr''' '''up''' '''down''' '''lwb''' '''upb''' '''lt''' '''le''' '''ge''' '''gt''' '''eq''' '''ne''' '''and''' '''or''' '''over''' '''mod''' '''elem''' '''minusab''' '''plusab''' '''timesab''' '''divab''' '''overab''' '''modab''' '''plusto''' '''is''' '''{{Not a typo|isnt}}'''}}
| {{Yes}}
| {{Yes}}
| {{No}}
| {{Yes}} <small>(prefix operators always have priority 10)</small>
| Infix operators are left associative, prefix operators are right associative
| {{Yes}}
| {{Yes}}
| {{Yes}}
|-
| [[APL (programming language)|APL]]
|Subtraction assignment
| {{mono|1=+ - × ÷ ⌈ ⌊ * ⍟ &#124; ! ○ ~ ∨ ∧ ⍱ ⍲ &lt; ≤ = ≥ > ≠ . @ ≡ ≢ ⍴ , ⍪ ⍳ ↑ ↓ ? ⍒ ⍋ ⍉ ⌽ ⊖ ∊ ⊥ ⊤ ⍎ ⍕ ⌹ ⊂ ⊃ ∪ ∩ ⍷ ⌷ ∘ → ← / ⌿ \ ⍀ ¨ ⍣ & ⍨ ⌶ ⊆ ⊣ ⊢ ⍠ ⍤ ⌸ ⌺ ⍸}}
|<code>x -= y</code>
| bgcolor="yellow" | Alphanumeric symbols need a ⎕ before the keyword
|<code>x = x - y</code>
| {{Yes}} <small>(first-order functions only)</small>
| {{Yes}}
| {{Yes}} <small>(higher-order functions only)</small>
| Higher-order functions precede first-order functions
| Higher-order functions are left associative, first-order functions are right associative
| {{Yes}}
| {{Yes}}
| {{Yes}} <small>(alphanumeric only)</small>
|-
| [[C (programming language)|C]]
|Multiplication assignment
| rowspan="3" | {{mono|1=() [] -> . ! ~ ++ -- + - * & / % << >> < <= > >= == != ^ <nowiki>|</nowiki> && <nowiki>||</nowiki> [[?:]] = += -= *= /= %= &= ^= |= <<= >>=}}
|<code>x *= y</code>
| {{mono|1=[[sizeof]]}}
|<code>x = x * y</code>
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{No}}
| {{No}}
|-
| [[C++]] ([[Operators in C and C++|more]])
|Division assignment
| {{mono|1=[[sizeof]] [[typeid]] [[new (C++)|new]] [[delete (C++)|delete]] [[Exception handling|throw]] [[decltype]] [[static_cast]] [[dynamic cast]] [[reinterpret_cast]] [[const_cast]]}}
|<code>x /= y</code>
| {{Yes}}
|<code>x = x / y</code>
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{No}}
|-
| [[Java (programming language)|Java]]
|Remainder assignment
| [[Java syntax#Instantiation|new]] [[instanceof]]
|<code>x %= y</code>
| {{Yes}}
|<code>x = x % y</code>
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{No}}
|-
| [[Eiffel (programming language)|Eiffel]]
|Exponentiation assignment
| {{mono|1=[] + - * / // = /= }}
|<code>x **= y</code>
| {{mono|1=not and or implies "and then" "or else" }}
|<code>x = x ** y</code>
| {{Yes}}
| {{Yes}}
| {{No}}
| {{Yes}}
| {{Yes}}
| {{No}}
| {{Yes}}
| {{Yes}}
|-
| [[Haskell (programming language)|Haskell]]
|Left shift assignment
| {{mono|1=+ - * / ^ ^^ ** == /= > < >= <= && &#x7c;&#x7c; >>= >> $ $! . ++ !! :}} <small>Many more in common libraries</small>
|<code>x <<= y</code>
| bgcolor="yellow" | The function's name must be put into backticks
|<code>x = x << y</code>
| {{Yes}}
| {{Yes}}
| {{No}}
| {{Yes}}
| {{Yes}}
| colspan="2" {{Yes}}, using [[Type class]]es
| {{Yes}}
|-
| [[Pascal (programming language)|Pascal]]
|Right shift assignment
| {{mono|1=* / + - = < > <> <= >= :=}}
|<code>x >>= y</code>
| [[Negation#Programming|not]] [[Integer division#Division of integers|div]] [[Modulo operation|mod]] [[Logical conjunction|and]] [[Logical disjunction|or]] in
|<code>x = x >> y</code>
| {{Yes}}
| {{Yes}}
| {{No}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{No}}
| {{No}}
|-
| [[Perl]]
|Unsigned right shift assignment
| {{mono|1=-> ++ -- ** ! ~ \ + - . =~ !~ * / % < > <= >= == != <=> ~~ & &#124; ^ &amp;&amp; &#124;&#124; ' ''{{Not a typo| // .. ... ?: = += -= *= , =>}} }}
|<code>x >>>= y</code>
| {{mono|1=print sort chmod chdir rand and or not xor lt gt le ge eq ne cmp x }}
|<code>x = x >>> y</code>
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{No}}
|-
| [[Perl 6]]
|Bitwise AND assignment
| {{mono|1=++ -- ** ! ~ ~~ * / + - . < > <= >= == != <=> & &#124; ^ &amp;&amp; &#124;&#124; //}} <ref>{{cite web |url=https://docs.perl6.org/language/operators |title=Operators}}</ref>
|<code>x &= y</code>
| {{mono|1=print sort chmod chdir rand and or not xor lt gt le ge eq ne leg cmp x xx}}
|<code>x = x & y</code>
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}<ref>{{cite web |url=https://docs.perl6.org/language/functions#Defining_Operators |title=Defining Operators}}</ref>
|-
| [[PHP]]
|Bitwise XOR assignment
| {{mono|1=[] ** ++ -- ~ @!<ref>{{cite web|url=http://php.net/manual/en/language.operators.errorcontrol.php|title=Error Controll Operators}}</ref> * / % + - . << >> < <= > >= == != === !== <> [[Spaceship operator|<=>]] & ^ <nowiki>|</nowiki> && <nowiki>||</nowiki> [[Null coalescing operator|??]] [[?:]] = += -= *= **= /= .= %= &= <nowiki>|=</nowiki> ^= <<= >>= }}
|<code>x ^= y</code>
| {{mono|1=clone new unset print echo isset [[instanceof]] [[Logical conjunction|and]] [[Logical disjunction|or]] [[Exclusive or|xor]]}}
|<code>x = x ^ y</code>
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{No}}
| {{No}}
| {{No}}
|-
| [[PL/I]]
|Bitwise OR assignment
| {{mono|1=( ) -> + - * / ** > &not;> >= = &not;= <= < &not;< &not; <nowiki>&</nowiki> <nowiki>|</nowiki> <nowiki>||</nowiki>}}
|<code><nowiki>x |= y</nowiki></code>
|
|<code><nowiki>x = x | y</nowiki></code>
| {{Yes}}
| {{Yes}}
| {{No}}
| {{Yes}}
| {{Yes}}
| {{No}}
| {{No}}
| {{No}}
|-
| [[Prolog]]
| {{mono|1=:- ?- ; , . =.. = \= < =< >= > == \== - + / *}}
| {{mono|1=spy nospy not is mod}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{No}}
| {{No}}
| {{Yes}}
|-
| [[Seed7]]
| {{mono|1={} [] -> ** ! + - * / << >> & >< <nowiki>|</nowiki> = <> > >= < <= <& := +:= -:= *:= /:= <<:= >>:= &:= @:=}}
| {{mono|1=conv varConv parse [[Complex conjugate|conj]] [[Integer division#Division of integers|div]] [[Remainder|rem]] [[Modulo operation|mdiv]] [[Modulo operation|mod]] times mult in [[Negation#Programming|not]] [[Logical conjunction|and]] [[Logical disjunction|or]] digits lpad rpad lpad0}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
|-
| [[Smalltalk]]
| (yes - Up to two characters<ref name="BinaryMessages">{{cite web|first=Adele|last=Goldberg|url=http://stephane.ducasse.free.fr/FreeBooks/BlueBook/Bluebook.pdf|title=Smalltalk-80: The Language and its Implementation, p. 27, ISBN 0-201-11371-6}}</ref>)
| bgcolor="yellow" | Alphanumeric symbols need a colon after the keyword
| {{No}}
| {{Yes}}
| {{Yes}}
| {{No}}
| {{No}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
|-
| [[Swift (programming language)|Swift]]
| Any Unicode symbol string except {{mono|1=.}}, including {{mono|1=! ~ + - * / % =+ =- =* =/ =% &+ &- &* =&+ =&- =&* && <nowiki>||</nowiki> << >> & <nowiki>|</nowiki> ^ == != < <= > >= ?? ... ..<}} in standard library
| {{mono|1=is as as?}}
| {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}} <small>(defined as partial order in precedence groups)</small>
| {{Yes}} <small>(defined as part of precedence groups)</small>
| {{Yes}}
| {{Yes}}
| {{Yes}}
|}
 
==See also==
== Bitwise Operators: ==
*[[Relational operator]]
 
==Notes==
The ''bitwise'' operators are similar to the logical operators, except that they work on a smaller scale -- binary representations of data.
{{notelist}}
 
==References==
The following operators are available:
{{reflist}}
 
[[Category:Operators (programming)| ]]
* <code>op1 & op2</code> -- The AND operator compares two bits and generates a result of 1 if both bits are 1; otherwise, it returns 0.
[[Category:Programming constructs]]
* <code>op1</code> | <code>op2</code> -- The OR operator compares two bits and generates a result of 1 if the bits are complementary; otherwise, it returns 0.
* <code>op1</code>''^'' <code>op2</code> -- The EXCLUSIVE-OR operator compares two bits and returns 1 if either of the bits are 1 and it gives 0 if both bits are 0 or 1.
* <code>~op1</code> -- The COMPLEMENT operator is used to invert all of the bits of the operand.
* <code>op1 >> op2</code> -- The SHIFT RIGHT operator moves the bits to the right, discards the far right bit, and assigns the leftmost bit a value of 0. Each move to the right effectively divides <code>op1</code> in half.
* <code>op1 << op2</code> -- The SHIFT LEFT operator moves the bits to the left, discards the far left bit, and assigns the rightmost bit a value of 0. Each move to the left effectively multiplies <code>op1</code> by 2.
 
== Miscellaneous Operators: ==
misc operator is miscellaneous operator, which is conditional operator which has 3 operands,The first operand is always evaluated first. If nonzero, the second operand is evaluated, and that is the value of the result. Otherwise, the third operand is evaluated, and that is the value of the result. Exactly one of the second and third operands is evaluated. The first operand may be a number, spot, or pointer. The second and third operands may either both be numbers, both spots, both pointers to the same type of object, or one may be a pointer or spot and the other the constant zero. In the first case the result is an int, and in the last two cases the result is a spot or a pointer of the same type.
 
The Micellaneous Operators are:
 
'''''.'''''
 
'''''new'''''
 
'''''()'''''
 
'''''[]'''''
 
'''''(type)'''''