Can anyone explain the role of fflush in this code? The output is 0 .. 1 .. 2 til 9. When I remove the fflush, it prints 0 1 2 3 4 5 6 7 8 9 at once after 10 seconds. Why?
Code:#include <stdio.h> #include <unistd.h> int main(void) { int i=0; printf("PID = %u\n", getpid()); while(i<10) { printf("%d ", i++); fflush(stdout); sleep(1); } printf("\n"); return 0; }