Why does printf() not print anything before sleep()?

前端 未结 4 581
死守一世寂寞
死守一世寂寞 2020-12-05 07:45

I\'m just learning C with Kernighan and Ritchie\'s book; I\'m in the basics of the fourth chapter (functions stuff). The other day I became curious about the sleep()

4条回答
  •  Happy的楠姐
    2020-12-05 08:12

    Buffering means that all the output is stored in a place (called buffer) and is output after a certain amount of data is present in it. This is done for efficiency reasons.

    Some (most?) implementations clear the buffer after a newline when writing to the console, so you can also try

    printf(" I like cows.\n");
    

    instead of the call to fflush()

提交回复
热议问题