Difficulty: Medium
Correct Answer: flushes all streams and specified streams.
Explanation:
Introduction / Context:fflush
ensures that buffered output is physically written to its destination. The exact scope depends on the argument passed to the function per ISO C and common extensions.
Given Data / Assumptions:
fflush(NULL)
to flush all open output streams.
Concept / Approach:
int fflush(FILE *stream)
flushes buffered output for the specified stream when stream
is non-NULL. Many implementations also define that fflush(NULL)
flushes all open output streams. Input streams are not affected by flushing in standard C (except where system-specific behavior exists).
Step-by-Step Solution:
Verification / Alternative check:
Testing with buffered stdout
shows that fflush(stdout)
forces immediate display; calling fflush(NULL)
(where available) flushes all outputs, useful before abnormal termination.
Why Other Options Are Wrong:
flushes only specified stream: Incomplete because many systems also support flushing all streams via NULL
.
flushes input/output buffer and flushes file buffer: Vague and do not capture the argument-based behavior.
Common Pitfalls:
fflush
—the standard does not require that.
Final Answer:
flushes all streams and specified streams.
Discussion & Comments