Should we break the default case in switch statement?

后端 未结 7 1462
北荒
北荒 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:57

    It depends on How default case is written.

    In the following case break is neccessary.

    switch ( input ) {
             default:
                printf( "Bad input, quitting!\n" );
                break;
            case 1:            /* Note the colon, not a semicolon */
                playgame();
                break;
            case 2:
                loadgame();
                break;
    
    0 讨论(0)
提交回复
热议问题