Should we break the default case in switch statement?

后端 未结 7 1460
北荒
北荒 2020-12-15 16:51

Assuming this example code (source):

#include 

void playgame()
{
    printf( \"Play game called\" );
}
void loadgame()
{
    printf( \"Load g         


        
7条回答
  •  时光说笑
    2020-12-15 17:55

    Actually, you don't need the break in default case. And as your checking, it's the same if you don't have break in default case.

    But in my opinion, you should have the break in default case, because:

    1. It make your code is have a form in every case.
    2. It's good with current compiler but maybe not with specific other compiler. So you should make it good well to prevent issue from future.

提交回复
热议问题