C: why are extra semicolons OK?

前端 未结 7 949
长发绾君心
长发绾君心 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 06:56

    An empty statement is legal in C. Since ; is the statement terminator, multiple ; are syntactically valid. Sometimes this is even useful: such as the for (;;) {/*code here*/} idiom.

    (Although some compilers will warn you in appropriate instances).

    Do note that, conceptually at least, the excess ; in that line are not part of the if block.

提交回复
热议问题