Difficulty: Easy
Correct Answer: Yes
Explanation:
Introduction / Context:fprintf
writes formatted text to a specified stream. This question examines whether the console is just another stream and how to use fprintf
for screen output.
Given Data / Assumptions:
stdout
and stderr
are available.
Concept / Approach:
Yes. The console is represented by standard output streams. Writing to stdout
or stderr
sends text to the terminal by default. fprintf(stdout, ...)
is equivalent to printf(...)
; fprintf(stderr, ...)
writes error messages that bypass buffering in some environments.
Step-by-Step Solution:
Verification / Alternative check:
Replacing printf
with fprintf(stdout, ...)
produces the same console output under normal conditions.
Why Other Options Are Wrong:
No: Incorrect because the console is accessible via the standard streams.
Common Pitfalls:
stdout
may go to a file or pipe depending on the shell.printf
can print to the console.
Final Answer:
Yes
Discussion & Comments