Page 55 - 6437
P. 55

When the above code is compiled and executed, it produces the following result:


                            This is part of outer switch

                            This is part of inner switch
                            Exact value of a is : 100

                            Exact value of b is : 200


                          The ? : Operator:
                          We have covered conditional operator ? : in the previous chapter which can be used to
                   replace if...else statements. It has the following general form:
                          Where Exp1, Exp2, and Exp3 are expressions. Notice the use and placement of the colon.

                 Exp1 ? Exp2 : Exp3;
                          The value of a ? expression is determined like this:
                          1.          Exp1 is evaluated. If it is true, then Exp2 is evaluated and becomes the value
                   of the entire ? expression.
                          2.          If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the
                   expression.





















































                                                                                                      57
   50   51   52   53   54   55   56   57   58   59   60