home *** CD-ROM | disk | FTP | other *** search
/ Microsoftware Monthly 19…2 Programming Power Tools / MASO9512.ISO / cpptutor / cpptutor.arj / TEXT / OPERATOR.TXT < prev   
Encoding:
Text File  |  1993-11-18  |  6.4 KB  |  108 lines

  1.               %C,1%Operator Summary and Precedence
  2. ┌──────────┬────────────────────────┬────────────────────────────┐
  3. │OPERATORS │OPERATOR TYPE           │SYNTAX                      │
  4. ├──────────┼────────────────────────┼────────────────────────────┤
  5. │::        │Scope Resolution        │class_name::member          │
  6. │::        │Global                  │::identifier                │
  7. ├──────────┼────────────────────────┼────────────────────────────┤
  8. │.         │Member Selection        │expression.member           │
  9. │->        │Member Selection        │pointer->member             │
  10. │[]        │Subscripting            │pointer[expression]         │
  11. │()        │Function Call           │expression(expression_list) │
  12. │()        │Aggregate               │type(expression_list)       │
  13. │sizeof    │size of object          │sizeof expression           │
  14. │sizeof    │size of type            │sizeof (type)               │
  15. ├──────────┼────────────────────────┼────────────────────────────┤
  16. │++        │post increment          │lvalue++                    │
  17. │++        │pre increment           │++lvalue                    │
  18. │--        │post decrement          │lvalue--                    │
  19. │--        │pre decrement           │--lvalue                    │
  20. │~         │complement              │~ expression                │
  21. │!         │not                     │! expression                │
  22. │-         │unary minus             │- expression                │
  23. │+         │unary plus              │+ expression                │
  24. │&         │address of              │& lvalue                    │
  25. │*         │dereference             │* expression                │
  26. │new       │create (allocate)       │new type                    │
  27. │delete    │destroy (de-allocate)   │delete pointer              │
  28. │delete[]  │destroy array           │delete [] pointer           │
  29. │()        │cast (type conversion)  │(type) expression           │
  30. ├──────────┼────────────────────────┼────────────────────────────┤
  31. │.*        │member section          │object.*pointer-to-member   │
  32. │->*       │member section          │object->*pointer-to-member  │
  33. ├──────────┼────────────────────────┼────────────────────────────┤
  34. │*         │multiply                │expr * expr                 │
  35. │/         │divide                  │expr / expr                 │
  36. │%         │modulo (remainder)      │                            │
  37. │          │                        │expr % expr                 │
  38. ├──────────┼────────────────────────┼────────────────────────────┤
  39. │+         │add (plus)              │expr + expr                 │
  40. │-         │subtract (minus)        │expr - expr                 │
  41. ├──────────┼────────────────────────┼────────────────────────────┤
  42. │<<        │shift left              │expr << expr                │
  43. │>>        │shift right             │expr >> expr                │
  44. ├──────────┼────────────────────────┼────────────────────────────┤
  45. │<         │less than               │expr < expr                 │
  46. │<=        │less than or equal      │expr <= expr                │
  47. │>         │greater than            │expr > expr                 │
  48. │>=        │greater than or equal   │expr >= expr                │
  49. ├──────────┼────────────────────────┼────────────────────────────┤
  50. │==        │equal                   │expr == expr                │
  51. │!=        │not equal               │expr != expr                │
  52. ├──────────┼────────────────────────┼────────────────────────────┤
  53. │&         │bitwise AND             │expr & expr                 │
  54. ├──────────┼────────────────────────┼────────────────────────────┤
  55. │^         │bitwise exclusive OR    │expr ^ expr                 │
  56. ├──────────┼────────────────────────┼────────────────────────────┤
  57. │|         │bitwise inclusive OR    │expr | expr                 │
  58. ├──────────┼────────────────────────┼────────────────────────────┤
  59. │&&        │logical AND             │expr && expr                │
  60. ├──────────┼────────────────────────┼────────────────────────────┤
  61. │||        │logical inclusive OR    │expr || expr                │
  62. ├──────────┼────────────────────────┼────────────────────────────┤
  63. │?:        │conditional expression  │expr ? expr : expr          │
  64. ├──────────┼────────────────────────┼────────────────────────────┤
  65. │=         │simple assignment       │lvalue = expr               │
  66. │*=        │multiple and assign     │lvalue *= expr              │
  67. │/=        │divide and assign       │lvalue /= expr              │
  68. │%=        │modulo and assign       │                            │
  69. │          │                        │lvalue %= expr              │
  70. │+=        │add and assign          │lvalue += expr              │
  71. │-=        │subtract and assign     │lvalue -= expr              │
  72. │<<=       │shift left and assign   │lvalue <<= expr             │
  73. │>>=       │shift right and assign  │lvalue >>= expr             │
  74. │&=        │AND and assign          │lvalue &= expr              │
  75. │|=        │inclusive OR and assign │lvalue |= expr              │
  76. │^=        │exclusive OR and assign │lvalue ^= expr              │
  77. ├──────────┼────────────────────────┼────────────────────────────┤
  78. │throw     │throw exception         │throw expr                  │
  79. ├──────────┼────────────────────────┼────────────────────────────┤
  80. │,         │comma (sequencing)      │expr , expr                 │
  81. └──────────┴────────────────────────┴────────────────────────────┘
  82.  
  83. Two operator characteristics determine how operands group with
  84. operators:  precedence and associativity.  Precedence is a
  85. priority system for grouping different types of operators with
  86. their operands.  Associativity provides a left-to-right or
  87. right-to-left order for grouping operands to operators that have
  88. the same precedence.  You can explicitly state the grouping of
  89. operands with operators by using parentheses.
  90.  
  91. Consider the expression:
  92.  
  93. a %C,1%+  %C,5%b %C,1%* %C,5%c %C,1%/ %C,5%d
  94.  
  95. Here is the same expression with parentheses to show how the
  96. operands are grouped with operators:
  97.  
  98. a%C,1% + ((%C,5% b %C,1%* %C,5%c%C,1%) / %C,5%d%C,1%)
  99.  
  100. The %C,1%+%C,5% is evaluated last because it has lower precedence than
  101. %C,1%*%C,5% or %C,1%/%C,5%.  The %C,1%*%C,5% is evaluated before the %C,1%/%C,5% because
  102. of associativity.
  103.  
  104. The operators are listed in order of precedence.  The primary
  105. scope resolution operator has the highest precedence, and the
  106. comma operator has the lowest.  Operators in a box have the same
  107. precedence.
  108.