stdout은 기본적으로 buffered된다(ISO기준이라 함).
이말이 무엇이냐면 printf가 New line character(\n)를 만나기 전까지 내용을 출력하지 않는다는 것이다.
예를 들어 아래와 같은 코드가 있다면
1 : printf("AAA");
2 : printf("BBB");
3 : printf("\n");
3 : printf("\n")이 실행될 때 AAABBB도 함께 출력된다.
이를 막고자 한다면 printf마다 fflush(stdout);을 통해 Flushing을 시켜주어야 하는데 귀찮은 일이다.
대신 setbuf(stdout, NULL);을 한번 실행하면 buffering되지 않는다.
출처 : http://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin