Operators in C and C Plus Plus
|
- The title of this article is incorrect because of technical limitations. The correct title is Operators in C and C++.
This is a list of operators in C++ programming language. Third column tells whether or not the operator in question also exists in C99 (and also in C89, since the two versions of the C language contain the same set of operators).
The following operators are sequence points in all three languages: &&, ||, ?:, 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.
Arithmetic Operators | |||||
Operator Name | Syntax | Is overloadable? | In C99? | ||
---|---|---|---|---|---|
Plus Operator (unary) | +a | Yes. | Yes. | ||
Addition Operator | a + b | Yes. | Yes. | ||
Addition Prefix Operator | ++a | Yes. | Yes. | ||
Addition Postfix Operator | a++ | Yes. | Yes. | ||
Addition Assignment Operator | a += b | Yes. | Yes. | ||
Negation Operator (unary) | -a | Yes. | Yes. | ||
Subtraction Operator | a - b | Yes. | Yes. | ||
Subtraction Prefix Operator | --a | Yes. | Yes. | ||
Subtraction Postfix 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. | ||
Modulus Operator | a % b | Yes. | Yes. | ||
Modulus Assignment Operator | a %= b | Yes. | Yes | ||
Comparison Operators | |||||
Operator Name | Syntax | Is overloadable? | In C99? | ||
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. | ||
Negation Operator | !a | Yes. | Yes. | ||
Logical And | a && b | Yes. | Yes. | ||
Logical Or | a || b | Yes. | Yes. | ||
Bitshift Operators | |||||
Operator Name | Syntax | Is overloadable? | In C99? | ||
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. | ||
Bitwise Operators | |||||
Operator Name | Syntax | Is overloadable? | In C99? | ||
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. | ||
Other Operators | |||||
Operator Name | Syntax | Is overloadable? | In C99? | ||
Assignment Operator | a = b | Yes. | Yes. | ||
Function Call Operator | a() | Yes. | Yes. | ||
Array Operator | a[] | Yes. | Yes. | ||
Dereference Operator | *a | Yes. | Yes. | ||
Arrow Operator | a-> | Yes. | Yes. | ||
Member Operator | a.b | No. | Yes. | ||
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. |
Notes
Some of the functions listed above are sometimes given longer form "names". For example, += and -= are often called PlusEqual and MinusEqual. This is also useful in performing internet searches, as major sites like google do not allow a search for "+=" for example.