Learn C++ in step-by-step lessons.
Conditional operator: ?
The question mark is the conditional operator. It is a ternary operator, it has three parts: the condition, the result if true, and the result if false.
The syntax is (Boolean expression)? true value: false value;
The conditional operator is used instead of if/else in very simple situations.
Goals:
- Be able to understand the conditional operator ? and write and evlauate code that uses it.
Objectives:
- Evaluate result of a conditional statement;
- Write a conditional statement.
Please study the material at each of the links below.
- Print pass or fail
- Tests if a month is valid
- Prints two numbers in order
- Finds the smallest
- Finds smallest and largest
- Calculate tip using conditional
Glossary for conditional lesson
Full Glossary