LearnFrenzy
Sign in Take a free test

C Input / Output · Input/Output MCQ · Question 8

When does feof() return true? Answer, explanation & discussion

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

When does feof(fp) return a non-zero value?

  • A As soon as the last byte has been read
  • B After a read operation has tried to go past the end of the file Correct
  • C When the file is empty, before any read
  • D After fclose()
Correct Answer: Option B

The end-of-file indicator is set by a read that fails. That is why while (!feof(fp)) runs one extra time; test the read function's result instead.

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