Odds and Ends http://cs.mst.edu Ternary Operator expression1 ? - - PowerPoint PPT Presentation

odds and ends
SMART_READER_LITE
LIVE PREVIEW

Odds and Ends http://cs.mst.edu Ternary Operator expression1 ? - - PowerPoint PPT Presentation

Odds and Ends http://cs.mst.edu Ternary Operator expression1 ? expression2 : expression3 http://cs.mst.edu Ternary Operator expression1 ? expression2 : expression3 http://cs.mst.edu Ternary Operator expression1 ? expression2 : expression3


slide-1
SLIDE 1

http://cs.mst.edu

Odds and Ends

slide-2
SLIDE 2

http://cs.mst.edu

Ternary Operator

expression1 ? expression2 : expression3

slide-3
SLIDE 3

http://cs.mst.edu

Ternary Operator

expression1 ? expression2 : expression3

slide-4
SLIDE 4

http://cs.mst.edu

Ternary Operator

expression1 ? expression2 : expression3

slide-5
SLIDE 5

http://cs.mst.edu

Ternary Operator

expression1 ? expression2 : expression3

slide-6
SLIDE 6

http://cs.mst.edu

Example #1

cout << num_pennies << " penn" << (num_pennies == 1 ? "y" : "ies") << endl;

slide-7
SLIDE 7

http://cs.mst.edu

Example #2

int val1, num1, bigger; cout<<“enter two numbers: “; cin>>val1>>num1; bigger = (val1 > num1 ? Val1 : num1); cout<<“the larger of your inputs is “ <<bigger<<endl;

slide-8
SLIDE 8

http://cs.mst.edu

Newlines

  • cout << “hello\n”;
  • \n ascii standard for linefeed - output buffered
  • cout << “hello” << endl;
  • endl clears std output buffer
slide-9
SLIDE 9

http://cs.mst.edu

Escape Sequences

  • \r – carriage return; moves cursor to the start of the line
  • \n - newline char; brings cursor to the next line
  • \t - tab character; used to tab output over some spaces
  • \a - alert; rings a bell in your computer
  • \\ - backslash; allows you to output a \ character
  • \’ - allows output of single tick
  • \” - allows output of quotes
  • \0 - NULL char; we’ll work with this later in the semester
  • \b - backspace
slide-10
SLIDE 10

http://cs.mst.edu

End of Session