1 / 9

Additional C++ Operators

Additional C++ Operators. Robert REaves. 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.

mingles
Download Presentation

Additional C++ Operators

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • ++someIntis 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<int>(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;

More Related