Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of the following program ?

#include\(\lt\)stdio.h\(\gt\)
main()
{
fprintf(stdout,"Hello, World!") ;
}

  • A.Hello, World!
  • B.No output
  • C.Compile error
  • D.Runtime error

Answer: C

The answer given by the Commission's key is Compile error (option C).

The program omits the return type of main(). Before the C99 standard such a declaration meant int main(), and an old compiler would print Hello, World! and exit. C99 and later removed that implicit int rule, so under a conforming modern compiler the declaration is an error or at best a diagnosed extension, and the key reads the program that way. The call fprintf(stdout, ...) is itself valid and is not the cause.

Option A is what a pre-C99 compiler would print, and it is why the question is open to debate; the keyed answer rests on the current standard. No output is wrong because stdout is flushed when the program ends, and runtime error is wrong because nothing in the program fails when it runs.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.