This is a list of operators in the C++ and C programming languages. All the operators listed exist in C++; the third column indicates whether an operator is also present in C. It should also be noted that C does not support operator overloading.
The following operators are sequence points in both languages (when not overloaded): &&, ||, ?:, and ,
C++ also contains the type conversion operators const_cast, static_cast, dynamic_cast, and reinterpret_cast which are not listed in the table for brevity. The formatting of these operators means that their precedence level is unimportant.
Those operators that are in C, with the exception of the comma operator, are also in Java, Perl, C#, and PHP with the same precedence, associativity, and semantics.
| Operators | Description | Associativity |
() | Parentheses (grouping) | Array subscriptleft-to-right |
++ -- | Prefix/postfix increment and decrement | Unary plus and minusright-to-left |
* / %
| Multiplication, division, and modulus (remainder) | left-to-right |
+ -
| Addition and subtraction | |
<< >>
| Bitwise left shift and right shift | |
< <= | Relational “less than” and “less than or equal to” | Relational “greater than” and “greater than or equal to”
|
== !=
| Relational “equal to” and “not equal to” | |
&
| Bitwise AND | |
^
| Bitwise XOR (exclusive or) | |
| Bitwise OR (inclusive or) | ||
&&
| Logical AND | |
| Logical OR | |
c?t:f
| Ternary conditional | right-to-left |
= | Direct assignment | Assignment by sum and difference|
,
| Comma | left-to-right |
| Operator Name | Syntax | Is overloadable? | In C? |
|---|---|---|---|
| Plus Operator (unary) | +a | Yes. | Yes. |
| Addition Operator | a + b | Yes. | Yes. |
| Prefix Increment Operator | ++a | Yes. | Yes. |
| Postfix Increment Operator | a++ | Yes. | Yes. |
| Addition Assignment Operator | a += b | Yes. | Yes. |
| Negation Operator (unary) | -a | Yes. | Yes. |
| Subtraction Operator | a - b | Yes. | Yes. |
| Prefix Decrement Operator | --a | Yes. | Yes. |
| Postfix Decrement Operator | a-- | Yes. | Yes. |
| Subtraction Assignment Operator | a -= b | Yes. | Yes. |
| Multiplication Operator | a * b | Yes. | Yes. |
| Multiplication Assignment Operator | a *= b | Yes. | Yes. |
| Division Operator | a / b | Yes. | Yes. |
| Division Assignment Operator | a /= b | Yes. | Yes. |
| Modulo Operator | a % b | Yes. | Yes. |
| Modulo Assignment Operator | a %= b | Yes. | Yes. |
| Operator Name | Syntax | Is overloadable? | In C? |
| Less Than Operator | a < b | Yes. | Yes. |
| Less Than Or Equal To Operator | a <= b | Yes. | Yes. |
| Greater Than Operator | a > b | Yes. | Yes. |
| Greater Than Or Equal To Operator | a >= b | Yes. | Yes. |
| Not Equal To Operator | a != b | Yes. | Yes. |
| Equal To Operator | a == b | Yes. | Yes. |
| Logical Negation Operator | !a | Yes. | Yes. |
| Logical And | a && b | Yes. | Yes. |
| Logical Or | a || b | Yes. | Yes. |
| Operator Name | Syntax | Is overloadable? | In C? |
| Left Shift | a << b | Yes. | Yes. |
| Left Shift + Assignment | a <<= b | Yes. | Yes. |
| Right Shift | a >> b | Yes. | Yes. |
| Right Shift + Assignment | a >>= b | Yes. | Yes. |
| Operator Name | Syntax | Is overloadable? | In C? |
| Bitwise Complement | ~a | Yes. | Yes. |
| Bitwise And | a & b | Yes. | Yes. |
| Bitwise And + Assignment | a &= b | Yes. | Yes. |
| Bitwise Or | a | b | Yes. | Yes. |
| Bitwise Or + Assignment | a |= b | Yes. | Yes. |
| Bitwise Xor | a ^ b | Yes. | Yes. |
| Bitwise Xor + Assignment | a ^= b | Yes. | Yes. |
| Operator Name | Syntax | Is overloadable? | In C? |
| Assignment Operator | a = b | Yes. | Yes. |
| Function Call Operator | a() | Yes. | Yes. |
| Array Operator | a* | Yes. | Yes. |
| Dereference Operator | *a | Yes. | Yes. |
| Reference Operator | &a | Yes. | Yes. |
| Arrow Operator | a->b | Yes. | Yes. |
| Member Operator | a.b | No. | Yes. |
| Dereferencing Member Operator | a.*b | No. | No. |
| Dereferencing Arrow Operator | a->*b | Yes. | No. |
| Cast Operator | (type) a | Yes. | Yes. |
| Comma Operator | a , b | Yes. | Yes. |
| Conditional | a ? b : c | No. | Yes. |
| Scope Resolution | a :: b | No. | No. |
| Sizeof Operator | sizeof a | No. | Yes. |
| Type Identification Operator | typeid (type) | No. | No. |
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Operators in C and C++".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world