Branch is instruction in a computer program that can cause a program to execute different task or statements based on a condition. Branching comparing variable value or function return value. There are 3 branching in C++.
- if-else
- switch-case
- ternary operator
Ternary Operator
Ternary operator is a simpler version of if-else. You can use ternary operator if you only need to choose between 2 values.
- Syntax : Condition?if_true:if_false;
Example :
Example
Input : 23 23 is an odd number