Is it possible to write statements after return?

后端 未结 5 1379
遇见更好的自我
遇见更好的自我 2021-01-20 18:13

Is the return statement the last statement inside main or is it possible to write statements after return?

#include 

        
5条回答
  •  春和景丽
    2021-01-20 18:22

    The only way you could usefully have code after a "return" is if the "return" statement is conditional.

    if (error) return 0;
    # All code invoked past this point knows error is false
    

    This isn't great coding style, you're creating code where there are 2+ ways to exit. When you need to debug it you'll find it more challenging to put in flags and "what happened when we exited" and so forth.

提交回复
热议问题