Discussion
What is the output of the following program ?
#include\(\lt\)stdio.h\(\gt\)
main()
{
fprintf(stdout,"Hello, World!") ;
}
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.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development