Presentation is loading. Please wait.

Presentation is loading. Please wait.

Additional C++ Operators ROBERT REAVES. Choosing a Looping Statement  Count-controlled loop, use for loop.  Event-controlled loop whose body should.

Similar presentations


Presentation on theme: "Additional C++ Operators ROBERT REAVES. Choosing a Looping Statement  Count-controlled loop, use for loop.  Event-controlled loop whose body should."— Presentation transcript:

1 Additional C++ Operators ROBERT REAVES

2 Choosing a Looping Statement  Count-controlled loop, use for loop.  Event-controlled loop whose body should execute once, use do- while loop.  Event-controlled loop and nothing is known about the first execution, use while loop.  When in doubt, use a while loop.  Infinite loop, break statements sometimes help.

3 Additional C++ Operators  P. 323 – 324

4 Assignment Operators and Assignment Expressions  Assignment Expression is a C++ expression with a value and the side effect of storing the expression value into a memory location.  delta = 2 * 12;  is an expressions, so you can use it anywhere an expression is allowed.  thirdInt = (secondInt = (firstInt = 20) + 10) + 5;  Expression Statement is a statement formed by appending a semicolon to an expression.  23;  2 * (alpha + beta)

5 Increment and Decrement Operators  ++someInt is pre-incrementation  Incrementing occurs before use.  someInt++ is post-incrementation  Use before incrementing occurs.

6 Bitwise Operators  <<, left shift  >>, right shift  &, bitwise AND  |, bitwise OR  Used for manipulating individual bits within a memory cell.

7 Cast Operation  Cast operation comes in three forms:  intVar = int(floatVar);// Functional notation  intVar = (int)floatVar;// Prefix notation  intVar = static_cast (floatVar);// Keyword notation  Use explicit type cast to avoid confusing code with implicit type coercion.

8 Sizeof()  Unary operator that yields the size, in bytes, of its operand.  sizeof(long);  cout << sizeof(int) << endl;

9 ?: Operator  Called the conditional operator, ternary (three-operand) operator.  Expression1? Expression2 : Expression3  if( a > b)  max = a;  else  max = b;  EQUIVLIENT TO:  max = (a > b) ? a : b;


Download ppt "Additional C++ Operators ROBERT REAVES. Choosing a Looping Statement  Count-controlled loop, use for loop.  Event-controlled loop whose body should."

Similar presentations


Ads by Google