http://www.cplusplus.com/reference/clibrary/cstdio/feof/
This page contains the famous but wrong pattern of using
feof() as the condition in a
while loop. It also uses the
%d conversion specifier to print a
long int variable.
1. The printed file size is one larger than the real file size.
2. But even before printing the file size, the program invokes undefined behavior, so it is not even guaranteed that the output is wrong or correct. It could be anything.
Who is able to fix the example? Oh wait, when the example is fixed the call to
feof() is no longer there, so the example would be unrelated to the topic. But maybe not, since lots of people use this pattern to copy files or read files. It should just be marked as clearly wrong.
(edit: oops, I overlooked the
n - 1 at the end, which is somewhat surprising. The example also does not explain why you need to subtract one. So the example is only wrong in one place.)