Odds and Ends
Ternary Operator
expression1 ? expression2 : expression3
Ternary Operator
expression1 ? expression2 : expression3
Ternary Operator
expression1 ? expression2 : expression3
Ternary Operator
expression1 ? expression2 : expression3
Example #1
cout <<num_pennies<< "penn"<< (num_pennies== 1 ? "y" : "ies")<<endl;
Example #2
intval1, num1, bigger;cout<<“enter two numbers: “;cin>>val1>>num1;bigger = (val1 > num1 ? Val1 : num1);cout<<“the larger of your inputs is “<<bigger<<endl;
Newlines
cout<< “hello\n”;\nasciistandard forlinefeed - output bufferedcout<< “hello” <<endl;endlclears std output buffer
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
End of Session
0
Embed
Upload