When you exit the program, how do these FILE* objects get closed and released?
They are closed by the C runtime code which is automatically linked to your program - the code that calls your main() function also calls exit() after main() returns.
From C99 §7.20.4.3/3:
Next, all open streams with unwritten buffered data are flushed, all open streams are closed, and all files created by the tmpfile function are removed.
POSIX (aligned with C99) spells it out better:
The exit() function shall then flush all open streams with unwritten buffered data and close all open streams.
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