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?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s