**Priority**- Higher priority operators take priority over lower priority ones. So, as every FORTRAN programmer knows,:-2 + 3 * 5

is 17 not 25. In the table operators are ordered in decreasing priority, although operators within a single box, for example add and subtract, operate at the same priority.**Association**- When selecting between two operators of the same priority, they operate according to their associativity, which is either:-

- R/L (right to left). Unary operators and assignment operators are right
to left. So
x=y=z

places the value z in x and y (not place y in x and z in y) - L/R (left to right). All other operators work left to right, so
expressions of the form:-
point -> member_func1(args1) -> member_func2(args2)

where one object's member function is called, and returns a pointer to a second object whose member function is then called.**Operator Summary**Symbol Name Assoc. Example :: scope resolution L/R *class_name::member*:: global L/R *::name*. member selection L/R *object.member*-> member selection L/R *pointer->member*[] subscripting L/R *pointer [ expr ]*() function call L/R *expr ( expr_list )*() value construction L/R *type ( expr_list )*++ post increment R/L *lvalue++*-- post decrement R/L *lvalue--*sizeof size of object R/L sizeof *expr*sizeof size of type R/L sizeof *( type )*++ pre increment R/L *++lvalue*-- pre decrement R/L *--lvalue*~ complement R/L *~ expr*! not R/L *! expr*- unary minus R/L *- expr*+ unary plus R/L *+ expr*& address of R/L *& lvalue** dereference R/L ** expr*new create R/L new *type*delete destroy R/L delete *pointer*delete [] destroy array R/L delete *[] pointer*() type cast R/L ( type ) *expr*.* member selection L/R *object .* pointer-to-member*->* member selection L/R *pointer ->* pointer-to-member** multiply L/R *expr * expr*/ divide L/R *expr / expr*% modulo L/R *expr % expr*+ add L/R *expr + expr*- subtract L/R *expr - expr*<< shift left L/R *expr << expr*>> shift right L/R *expr >> expr*< less than L/R *expr < expr*<= less than or equal L/R *expr <= expr*> greater than L/R *expr > expr*>= greater than or equal L/R *expr >= expr*== equal L/R *expr == expr*!= not equal R/L *expr != expr*& bitwise AND L/R *expr & expr*^ bitwise exclusive OR R/L *expr ^ expr*| bitwise inclusive OR L/R *expr | expr*&& logical AND L/R *expr && expr*|| logical inclusive OR L/R *expr || expr*? : conditional expression L/R *expr ? expr : expr*= simple assignment R/L *lvalue = expr**= multiply and assign R/L *lvalue *= expr*/= divide and assign R/L *lvalue /= expr*%= modulo and assign R/L *lvalue %= expr*+= add and assign R/L *lvalue += expr*-= subtract and assign R/L *lvalue -= expr*<<= shift left and assign R/L *lvalue <<= expr*>>= shift right and assign R/L *lvalue >>= expr*&= AND and assign R/L *lvalue &= expr*^= exclusive OR and assign R/L *lvalue ^= expr*|= inclusive OR and assign R/L *lvalue |= expr*throw throw exception R/L throw *expr*, comma L/R *expr , expr*Where:-

*class_name*- is the name of a class.*member*- is a member function or a data member.*object*- is an expression producing an object.*pointer*- is an expression producing a pointer.*expr*- is an expression.*lvalue*- is an lvalue i.e. a value that can be modified.*type*- is the name of a type, either fundamental or user defined.

## KISS = Keep It Simple Stupid!

Now you have seen a list of over 50 operator with the rules for combining them. So it is possible to compose long expression with multiple operators and the compiler will perfectly understand its meaning. Its even possible that you do (at least when you wrIte it). Whether anyone else will without effort is another story of course. When it comes to expression complexity, apply the KISS rule. HEP code tends to be looked at by a variety of people with a variety of computing skills, by keeping code transparent, the chances increase that someone will spot the bug you have missed!

Go Back to the The C++ Crib Top Page

If you have any comments about this page please send them to Nick West