C++ Nested if....else
C++ Nested if....else
The if.....else statement executes two different codes depending upon whether the test expression is true or false. Sometimes, a choice has to be made from more than 2 possibilities.
The nested if...else statement executes allows you to check for multiple test expressions and execute different codes for more than two conditions.
Syntax of Nested if...else
C++ Nested if....else
Output:
Conditional/Ternary Operator ?:
A ternary operator operates on three operand which can be used instead of if..else statement.Consider this code:
You can replace the above code with:
a = ( a < b ) ? b : -b;
Ternary operator is more readable than a if...else statement for short conditions.
a = ( a < b ) ? b : -b;
Ternary operator is more readable than a if...else statement for short conditions.
0 comments:
Post a Comment