When does printf fail to print?

后端 未结 5 1969
梦谈多话
梦谈多话 2020-12-17 10:42

printf function in c doesn\'t always print the output on screen. For example if you forget to put \\n at the end of string you are printfing you sometimes don\'t get the o/p

5条回答
  •  星月不相逢
    2020-12-17 11:13

    its not that printf won't always print, its that it isn't guaranteed to print immediately. This means that if you are using it for debugging purposes, then you can't guarantee that it will happen exactly when it does in the code. If you want to make sure that it does print exactly when you said it call fflush(stdout).

    Note: You typically don't want to use fflush(stdout) unless you are debugging, its really resource intensive and if you care about speed performance at all it has the potential to slow you down.

提交回复
热议问题