article

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.

Operator precedence


The following is a table that lists the precedence and associativity of all the operators in the C programming language. Operators on the same row are evaluated with the same precedence, in the given direction.

*
.
->Array subscript
Element selection by reference
Element selection by pointer +-
!~
(type)
*
&
sizeofUnary plus and minus
Logical NOT and bitwise zero's complement
Type cast
Dereference
Reference (address-of)
Size of >>=Relational “greater than” and “greater than or equal to” +=-=
*=/=%=
<<=>>=
&=^=|=Assignment by sum and difference
Assignment by product, dividend, and remainder
Assignment by bitwise shift
Assignment by bitwise AND, XOR, and OR
Operators Description Associativity
()
Parentheses (grouping)
left-to-right
++ --
Prefix/postfix increment and decrement
right-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 “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
, Comma left-to-right

Table


Arithmetic Operators

Comparison Operators

Bitshift Operators

Bitwise Operators

Other Operators

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.

Notes


Some of the operators 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.

C programming language | C++

 

This article is licensed under the GNU Free Documentation License. It uses material from the "Operators in C and C++".

Home Pageartsbusinesscomputersgameshealthhospitalshomekids & teensnewsphysiciansrecreationreferenceregionalscienceshoppingsocietysportsworld