Re: C Interview Questions



Adrian said:

Richard Heathfield wrote:
dhruvaraj@xxxxxxxxx said:

6. .Identify the correct argument for the function call fflush() in ANSI
C:

None of the candidate answers is uniquely correct. Three are wrong, and
stdout is only /one/ correct argument for fflush.

Richard, could you tell me why all three are wrong.

Um, make that two. :-) (And neither of the other two is uniquely correct,
so it's still a big deal from a getting-the-right-answer perspective.)
While there isn't much point in fflushing stderr, it's legal. But fflush is
only well-defined for streams open for update or output, which stdin is
not. So the answer cannot be A, because that would suggest C is wrong,
cannot be B because it's wrong, cannot be C because that would suggest A is
wrong, and cannot be D because B is wrong.

Also the standard says you can pass NULL to fflush to flush all open
streams.

Indeed, which is another reason that there is no such thing as *the* correct
argument to fflush.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages

  • Re: Two questions about a program in C
    ... executed the program again and fflush didn't work anymore! ... I buill the source with VC6 and XCode but I didn't have problems. ... also in the ansi '89 of C? ...
    (comp.lang.c)
  • Re: scanf behaviour
    ... Richard Heathfield wrote: ... U haven't provided any reference for your claim that fflush(stdin) is ... If stream points to an output stream or an update stream in which ...
    (comp.lang.c)
  • Re: C Interview Questions
    ... Richard Heathfield wrote: ... and stdout is only /one/ correct argument for fflush. ... I thought stdin, stdout, stderr where all macros to FILE * for the 3 streams. ... Now the standard does say for buffered streams, ...
    (comp.lang.c)
  • Re: reading a file in reverse order (bootom-top)
    ... Richard Heathfield wrote: ... > CBFalconer wrote: ... Burn it if you have it. ... >> Also missing any fflush. ...
    (comp.lang.c)
  • Re: C Interview Questions
    ... Richard Heathfield wrote: ... streams. ... argument to fflush. ... That's how English works. ...
    (comp.lang.c)