LearnFrenzy
Sign in Take a free test

C Input / Output · Input/Output MCQ · Question 12

Is fflush(stdin) correct in standard C? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

Is fflush(stdin) a portable way to discard pending input?

  • A Yes, it clears the input buffer everywhere
  • B No – fflush is defined only for output (or update) streams; on input streams the behaviour is undefined Correct
  • C Yes, but only on Linux
  • D No, it closes stdin
Correct Answer: Option B

Some libraries allow it as an extension, but standard C does not. Portable code reads and discards: while ((c = getchar()) != '\n' && c != EOF) {}.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links