Practical use of extra braces in C

前端 未结 4 644
时光取名叫无心
时光取名叫无心 2021-01-07 11:20

I know {} are used to separate entities such as functions, classes and conditional branching, but what other use would they have here?

#import &         


        
4条回答
  •  梦谈多话
    2021-01-07 11:54

    you can introduce a new scope, which then allows you to introduce new variables.... which can be useful in C89. Not too normal though, but occasionally useful.

    {
      int x =2 ;
      printf("%d", x);
      {
        int y = 7;
        printf("%d", y);
      }
    }
    

提交回复
热议问题