C++ Switch Cases -


i doing quiz online based on c++ switch statement. came across question , have fair understanding of how switch statements work 1 question made absolutely no sense me. can please explain?

screenshot!

why answer d , not c? case 2: default case or what? quiz can found at: http://www.cprogramming.com/tutorial/quiz/quiz5.html

here's how code behaves.

  • x equal 0
    • so cout<<"zero"; executed.
  • since there's no break; after it,
    • the second case executed: cout<<"hello world";

and since cout<<"something"; doesn't add newline after printing, they're printed single word.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -