Is if(TRUE) a good idea in C?

后端 未结 17 3404
忘了有多久
忘了有多久 2021-02-19 01:19

In the C programming language, it is my understanding that variables can only be defined at the beginning of a code block, and the variable will have the scope of the block it w

17条回答
  •  遥遥无期
    2021-02-19 01:45

    You don't even need an if statement. You can create blocks with {}

    That should probably be a separate function however.

    Example here:

    #include 
    
    int
    main(int argc, char **argv) {
        int i = 0;
        {
            int i = 10;
            printf("%d\n", i);
        }
        printf("%d\n", i);
    }
    

提交回复
热议问题