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. Are there some other conditions when printf doesn't print. I remember someone saying that there are 7 such conditions. Can you guys please help.
Standard out is a buffered stream, it is not guaranteed to flush unless a newline is put in, the stream is closed, or the program exits normally. If the program exits abnormally, it is possible for the stream to not flush. Standard out is line buffered, which is why a newline will flush it. There are buffers that will not flush with a newline.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With