Introduction to C / C++ Programming
Decision and Branching Concepts

Boolean Variables and Data Type

Relational Operators

Operator
Meaning
A > B
True ( 1 ) if A is greater than B, false ( 0 ) otherwise
A < B
True ( 1 ) if A is less than B, false ( 0 ) otherwise
A >= B
True ( 1 ) if A is greater than or equal to B, false ( 0 ) otherwise
A <= B
True ( 1 ) if A is less than or equal to B, false ( 0 ) otherwise
A = = B
True ( 1 ) if A is exactly equal to B, false ( 0 ) otherwise
A != B
True ( 1 ) if A is not equal to B, false ( 0 ) otherwise

Logical Operators

Operator
Meaning
A && B
A AND B - True ( 1 ) if A is true AND B is also true, false ( 0 ) otherwise
A | | B
A OR B - True ( 1 ) if A is true OR B is true, false ( 0 ) otherwise
! A
NOT A - True ( 1 ) if A is false ( 0 ), false ( 0 ) if A is true ( non-zero ).

if-else

switch

The Conditional Operator

Earlier we looked at unary and binary operators under C.  In addition, the C language contains one ternary operator, known as the conditional operator, ?:

condition ?  true_clause : false_clause
        if( error < tolerance )
            step *=  2.0;
        else
            step =  1.0;

        if( x != 0.0 )
            z /= x;
        else
            z =  infinite;

        if( x > 0.0 )
            sign =  1.0;
        else if ( x = = 0.0 )
                sign =  0.0;
        else sign = -1.0;

Related Topics

The following topics are not covered here, but may be found in many books on C/C++;