[ fromfile: operators.xml id: operators ]
Operators fall into broad classifications according to their primary use.
Assignment operators |
= , += , *= , ... |
Arithmetic operators |
+ , - , * , / , %
|
Relational operators |
< , <= , > , >= , == , !=
|
Logical operators |
&&, ||, !
|
Bitwise operators |
& , | , ^ , ~ , << , >>
|
Memory management operators |
|
Pointer and access operators |
* , & , . , -> , [] , ()
|
Scope resolution operators |
::
|
Miscellaneous operators | conditional(?: ), comma(, ) |
The C++ standard defines certain keywords that act as aliases for some of the operator symbols:
Table 19.1. Operator Aliases
Operator | Alias |
---|---|
&&
| and |
&
| bitand |
&=
| and_eq |
||
| or |
|
| bitor |
|=
| or_eq |
^
| xor |
^=
| xor_eq |
!
| not |
!=
| not_eq |
~
| compl |
Operators have predefined meanings for built-in types, but not all operators are defined for all built-in types.
Operators have the following special characteristics:
Precedence
Associativity
Number of required operands
Table 19.2 lists all the C++ operators and their characteristics, grouped by precedence and purpose, with groups of highest precedence listed first.
The Operands column contains the number of operands that the operator requires.
The Description column contains the conventional meaning of the operator for built-in types.
The A column indicates the associativity that governs how an expression is evaluated if the same operator occurs more than once.
L indicates left-to-right associativity. Example:
d = a + b + c; // a+b is evaluated first, then (a+b)+c
assignment is evaluated last because of lower precedence.
R indicates right-to-left associativity:
c = b = a; // a is assigned to b, then to c.
The Ovl column indicates whether the operator may be overloaded (redefined) for custom types.
The possible values for that column are
Y: This operator can be overloaded as a global or member function.
M: This operator can be overloaded only as a class member function.
N: This operator cannot be overloaded.
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |