Reputation: 31597
When you exit the program, how do these FILE*
objects get closed and released?
Upvotes: 2
Views: 449
Reputation: 2131
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.
Upvotes: 6
Reputation: 182664
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.
Upvotes: 4