C++ is one of the most versatile languages in the world. It is used nearly everywhere for everything… systems programming (operating systems, device drivers, database engines, embedded, Internet of Things, etc.)

Enter Header Image Headline Here

Saturday 15 April 2017

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.


0 comments:

Post a Comment

Popular Posts

Recent Posts

Categories

Unordered List

Text Widget