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

后端 未结 3 838
悲哀的现实
悲哀的现实 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:41

    When main() exits, all open streams are closed... to include stdout. Closing the open stream flushes stdout and what you've written to the buffer gets committed with or without the newline.

提交回复
热议问题