Is there a guarantee of stdout auto-flush before exit? How does it work?

后端 未结 3 836
悲哀的现实
悲哀的现实 2021-01-17 12:08

Here is the code (valid C and C++)

#include 

int main() {
    printf(\"asfd\");
    // LINE 1
    return 0;
}

If in line 1

3条回答
  •  一生所求
    2021-01-17 12:42

    This is accomplished by these two sections in the C++ language specification:

    [basic.start.main]

    A return statement in main has the effect of leaving the main function and calling exit with the return value as the argument.

    and

    [lib.support.start.term]

    The function exit has additional behavior in this International Standard:

    • ...
    • Next, all open C streams with unwritten buffered data are flushed.
    • ...

提交回复
热议问题