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

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -