home *** CD-ROM | disk | FTP | other *** search
- %C,1%Operator Summary and Precedence
- ┌──────────┬────────────────────────┬────────────────────────────┐
- │OPERATORS │OPERATOR TYPE │SYNTAX │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │:: │Scope Resolution │class_name::member │
- │:: │Global │::identifier │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │. │Member Selection │expression.member │
- │-> │Member Selection │pointer->member │
- │[] │Subscripting │pointer[expression] │
- │() │Function Call │expression(expression_list) │
- │() │Aggregate │type(expression_list) │
- │sizeof │size of object │sizeof expression │
- │sizeof │size of type │sizeof (type) │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │++ │post increment │lvalue++ │
- │++ │pre increment │++lvalue │
- │-- │post decrement │lvalue-- │
- │-- │pre decrement │--lvalue │
- │~ │complement │~ expression │
- │! │not │! expression │
- │- │unary minus │- expression │
- │+ │unary plus │+ expression │
- │& │address of │& lvalue │
- │* │dereference │* expression │
- │new │create (allocate) │new type │
- │delete │destroy (de-allocate) │delete pointer │
- │delete[] │destroy array │delete [] pointer │
- │() │cast (type conversion) │(type) expression │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │.* │member section │object.*pointer-to-member │
- │->* │member section │object->*pointer-to-member │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │* │multiply │expr * expr │
- │/ │divide │expr / expr │
- │% │modulo (remainder) │ │
- │ │ │expr % expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │+ │add (plus) │expr + expr │
- │- │subtract (minus) │expr - expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │<< │shift left │expr << expr │
- │>> │shift right │expr >> expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │< │less than │expr < expr │
- │<= │less than or equal │expr <= expr │
- │> │greater than │expr > expr │
- │>= │greater than or equal │expr >= expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │== │equal │expr == expr │
- │!= │not equal │expr != expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │& │bitwise AND │expr & expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │^ │bitwise exclusive OR │expr ^ expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │| │bitwise inclusive OR │expr | expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │&& │logical AND │expr && expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │|| │logical inclusive OR │expr || expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │?: │conditional expression │expr ? expr : expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │= │simple assignment │lvalue = expr │
- │*= │multiple and assign │lvalue *= expr │
- │/= │divide and assign │lvalue /= expr │
- │%= │modulo and assign │ │
- │ │ │lvalue %= expr │
- │+= │add and assign │lvalue += expr │
- │-= │subtract and assign │lvalue -= expr │
- │<<= │shift left and assign │lvalue <<= expr │
- │>>= │shift right and assign │lvalue >>= expr │
- │&= │AND and assign │lvalue &= expr │
- │|= │inclusive OR and assign │lvalue |= expr │
- │^= │exclusive OR and assign │lvalue ^= expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │throw │throw exception │throw expr │
- ├──────────┼────────────────────────┼────────────────────────────┤
- │, │comma (sequencing) │expr , expr │
- └──────────┴────────────────────────┴────────────────────────────┘
-
- Two operator characteristics determine how operands group with
- operators: precedence and associativity. Precedence is a
- priority system for grouping different types of operators with
- their operands. Associativity provides a left-to-right or
- right-to-left order for grouping operands to operators that have
- the same precedence. You can explicitly state the grouping of
- operands with operators by using parentheses.
-
- Consider the expression:
-
- a %C,1%+ %C,5%b %C,1%* %C,5%c %C,1%/ %C,5%d
-
- Here is the same expression with parentheses to show how the
- operands are grouped with operators:
-
- a%C,1% + ((%C,5% b %C,1%* %C,5%c%C,1%) / %C,5%d%C,1%)
-
- The %C,1%+%C,5% is evaluated last because it has lower precedence than
- %C,1%*%C,5% or %C,1%/%C,5%. The %C,1%*%C,5% is evaluated before the %C,1%/%C,5% because
- of associativity.
-
- The operators are listed in order of precedence. The primary
- scope resolution operator has the highest precedence, and the
- comma operator has the lowest. Operators in a box have the same
- precedence.
-