other conditional methods. conditional operator conditional operator (?:) conditional operator ( ?:...
Post on 01-Jan-2016
Embed Size (px)
Pathway Introduction: Information Technology
Other Conditional MethodsConditional OperatorConditional Operator (?:)Conditional operator (?:) Ternary operator: 3 argumentsexpression1 ? expression2 : expression3
If expression1 is true, result is expression2false, result is expression33Conditional Operator (?:)Example: int max = (a >= b) ? a : b;
Short for: int max;if (a >= b) max = a;else max = b;4Common UsePick one of two values inside larger expression:
Switch StatementComparing ifelse with ifsMethod 1:if( month == 1) cout