The document discusses the ternary operator, a shorthand version of an if/else statement that can replace multiple lines of code with a single line. It has three operands: a condition, an expression to execute if the condition is true, and an expression to execute if the condition is false. An example demonstrates assigning a string variable the value of either "GOOD DAY." or "GOOD EVENING." depending on whether the value of a time variable is less than 18.
The document discusses the ternary operator, a shorthand version of an if/else statement that can replace multiple lines of code with a single line. It has three operands: a condition, an expression to execute if the condition is true, and an expression to execute if the condition is false. An example demonstrates assigning a string variable the value of either "GOOD DAY." or "GOOD EVENING." depending on whether the value of a time variable is less than 18.
The document discusses the ternary operator, a shorthand version of an if/else statement that can replace multiple lines of code with a single line. It has three operands: a condition, an expression to execute if the condition is true, and an expression to execute if the condition is false. An example demonstrates assigning a string variable the value of either "GOOD DAY." or "GOOD EVENING." depending on whether the value of a time variable is less than 18.
C++ SERIES LECTURE#11 SHORT HAND IF...ELSE (TERNARY OPERATOR) SHORT HAND IF...ELSE (TERNARY OPERATOR)
• THERE IS ALSO A SHORT-HAND IF ELSE, WHICH IS KNOWN AS THE TERNARY
OPERATOR BECAUSE IT CONSISTS OF THREE OPERANDS. IT CAN BE USED TO REPLACE MULTIPLE LINES OF CODE WITH A SINGLE LINE. IT IS OFTEN USED TO REPLACE SIMPLE IF ELSE STATEMENTS: SYNTAX