411 REFERENCE · Wikibooks
C++ Programming/Operators Table
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Table of operators
Operators in the same group have the same precedence and the order of evaluation is decided by the associativity (left-to-right or right-to-left). Operators in a preceding group have higher precedence than those in a subsequent group.
Binding of operators actually cannot be completely described by "precedence" rules, and as such this table is an approximation. Correct understanding of the rules requires an understanding of the grammar of expressions.
OperatorsDescriptionExample UsageAssociativityScope Resolution Operator—::unary scope resolution operatorfor globals::NUM_ELEMENTS::binary scope resolution operatorfor class and namespace membersstd::coutFunction Call, Member Access, Post-Increment/Decrement Operators, RTTI and C++ CastsLeft to right()function call operatorswap (x, y)[]array index operatorarr [i].member access operatorfor an object of class/union typeor a reference to itobj.member->member access operatorfor a pointer to an object ofclass/union typeptr->member++ --post-increment/decrement operatorsnum++typeid()run time type identification operatorfor an object or typetypeid (std::cout)typeid (std::iostream)static_cast<>()dynamic_cast<>()const_cast<>()reinterpret_cast<>()C++ style cast operatorsfor compile-time type conversionSee Type Casting for more infostatic_cast<float> (i)dynamic_cast<std::istream> (stream)const_cast<char*> ("Hello, World!")reinterpret_cast<const long*> ("C++")type()functional cast operator(static_cast is preferredfor conversion to a primitive type)float (i)also used as a constructor callfor creating a temporary object, esp.of a class typestd::string ("Hello, world!", 0, 5)Unary OperatorsRight to left!, notlogical not operator!eof_reached~, complbitwise not operator~mask+ -unary plus/minus operators-num++ --pre-increment/decrement operators++num&, bitandaddress-of operator&data*indirection operator*ptrnewnew[]new()new()[]new operatorsfor single objects or arraysnew std::string (5, '*')new int [100]new (raw_mem) intnew (arg1, arg2) int [100]deletedelete[]delete operatorfor pointers to single objects or arraysdelete ptrdelete[] arrsizeofsizeof()sizeof operator for expressions or typessizeof 123sizeof (int)(type)C-style cast operator (deprecated)(float)iMember Pointer OperatorsRight to left.*member pointer access operatorfor an object of class/union typeor a reference to itobj.*memptr->*member pointer access operatorfor a pointer to an object ofclass/union typeptr->*memptrMultiplicative OperatorsLeft to right* / %multiplication, division andmodulus operatorscelsius_diff * 9 / 5Additive OperatorsLeft to right+ -addition and subtraction operatorsend - start + 1Bitwise Shift OperatorsLeft to right<<>>left and right shift operatorsbits << shift_lenbits >> shift_lenRelational Inequality OperatorsLeft to right< > <= >=less-than, greater-than, less-than orequal-to, greater-than or equal-toi < num_elementsRelational Equality OperatorsLeft to right== !=, not_eqequal-to, not-equal-tochoice != 'n'Bitwise And OperatorLeft to right&, bitand bits & clear_mask_complementBitwise Xor OperatorLeft to right^, xor bits ^ invert_maskBitwise Or OperatorLeft to right|, bitor bits | set_maskLogical And OperatorLeft to right&&, and arr != 0 && arr->len != 0Logical Or OperatorLeft to right||, or arr == 0 || arr->len == 0Conditional OperatorRight to left?: size >= 0 ? size : 0Assignment OperatorsRight to left=assignment operatori = 0+= -= *= /= %=&=, and_eq|=, or_eq^=, xor_eq <<= >>=shorthand assignment operators(foo op= bar representsfoo = foo op bar)num /= 10Exceptions—throw throw "Array index out of bounds"Comma OperatorLeft to right, i = 0, j = i + 1, k = 0