the conditional expression operatoran alternate


The Conditional Expression Operator

An alternate method to using a simple if-else construct is the conditional expressions operator, ?:

 

A conditional expression operator is a ternary operator, it has three operand, whose general format is:

 

expression1 ? expression2 : expression3

 

Here the expression1 is evaluated first, if it is true then the expression 2 is the value of the conditional operator, otherwise the expression 3 is the value.

 

e.g.

                The if else construct

 

if(a>b)

 {

z = a;

 }

else

 {

                z = b;

                       }

 

                This can be written as

 

                                z = (a>b) ? a: b;

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: the conditional expression operatoran alternate
Reference No:- TGS0309264

Expected delivery within 24 Hours