#include <stdlib.h>
#include <stdio.h>
int sum;//sum is a global variable
Main ()
{
int i;//i is a local variable
sum = 0;
for (i = 1;i <= 5; i++)//iterate i from 1 to 5
{
printf ("The value of I is%d/n", i);
Fflush (stdout);//flush the buffer
sum + = i;
}
printf ("The sum is%d/n", sum);
Exit (0);//terminate the program
}
This simple C program uses fflush (stdout) to empty the buffer and force the results to appear on the screen immediately.
General Writing C program, I have only used the printf (...). ), add fflush (stdout) seems to be no different, are immediately show the results, but with fork () when the effect is different.
#include <stdio.h>
#include <unistd.h>
int main ()
{
printf ("Hello");
Fflush (stdout);
Fork ();
return 0;
}
Invoke printf (..... , the output is generally cached by the standard library and may not necessarily be written to the output device in time, but Fflush (stdout) can force the output of the cached content.
Do not know the above understanding is right, look at the master pointing ...