printf 不能直接写到界面,先写到缓冲区。将缓冲区加载到界面满足的条件有:
1.写入的字符遇到 '\n'
如图,print.c文件中有代码:

输出结果:(先输出Hello,停3秒,再输出World)

2.调用 fflush(stdout) 函数时:
如图,print.c文件中有代码:

输出结果:

3.程序结束(exit(0) 或 return ;)
如图,有print.c文件:

输出结果:

满足以上三个条件之一缓冲区就会刷新。此时,我们还应知道两个函数:
(1) _exit(0) 函数:程序结束,不刷新缓冲区。
示例:print.c文件中程序如下:

结果显示:

由于不刷新缓冲区,因此界面上看不到"Hello World".
(2) atexit() 函数:注册进程退出。
示例:print.c文件代码如下图

显示结果:

|