Theory Questions.

Flow Of Control – Theory Questions.

Q1. How is the if..else if combination more general than a switch statement?

Or

Q1. Difference between if..else if combination and a switch statement?

Q2. What is a “fall through”?

Q3. Consider the following two code fragments for counting spaces and newlines:

//version 1

:

if ( ch= = ‘  ‘ )

        spaces + + ;

if ( ch = = ‘ \ ‘ )

        newlines + + ,

//version 2

:

if ( ch= = ‘  ‘ )

        spaces + + ;

else if ( ch = = ‘ \n ‘ )

        newlines + + ;

What advantages, if any, does the second version have over the first?

Leave a Reply

Your email address will not be published. Required fields are marked *