C: why are extra semicolons OK?

前端 未结 7 871
长发绾君心
长发绾君心 2021-01-25 06:20
#include 

int main() {
    int a = -1, b = -10, c = 5;
    if (a > b)
        printf(\"Hello World\");
    else
        printf(\"Get out World\");;;;;         


        
7条回答
  •  情话喂你
    2021-01-25 07:01

    Extra semicolons in general are not "OK".

    For example, changing your code slightly:

    #include 
    
    int main() {
        int a = -1, b = -10, c = 5;
        if (a > b)
            printf("Hello World");;;;;;
        else
            printf("Get out World");
    }
    

    That won't even compile.

    Another example, and this one does compile:

       ...
    
       int done = 0;
    
       ...
    
       while ( !done );
       {
           ...
    
           done = 1;
       }
    
       ...
    

提交回复
热议问题