GATE / CS ARCHIVE

GATE CSE 2005 / QUESTION 32

Removing a function prototype

Programming in C · Structures & Declarations · Full GATE CSE 2005 paper

GATE 2005, Q32 2 marks · MCQ
Report issue

Structures & Declarations

Question 32, GATE 2005: Program declares double foo(double) before main. main declares double da, db, obtains da through omitted input code, and assigns db=foo(da). Later definition double foo(double a){return a;}. If the initial declaration is removed, choose A no diagnostic; B harmless warnings; C type-mismatch warnings with unintended results; D compile errors. Distinguish standard-required diagnostic from implementation severity.
Question 32, GATE 2005: Program declares double foo(double) before main. main declares double da, db, obtains da through omitted input code, and assigns db=foo(da). Later definition double foo(double a){return a;}. If the initial declaration is removed, choose A no diagnostic; B harmless warnings; C type-mismatch warnings with unintended results; D compile errors. Distinguish standard-required diagnostic from implementation severity.
Tap to enlarge
Your answer
Answer & solution

Answer: D in ordinary C compilation (no official key was published)

Without the declaration, foo is called before its type is known. Modern C requires a declaration; historical implicit-int rules would assume an int-returning function, which conflicts with the later double-returning definition. A diagnostic is therefore required, and conventional compilers reject the conflicting types, D. C specifies required diagnostics rather than an absolute distinction between a warning and a fatal error, so exact compiler behavior depends on mode/extensions. The commented input of da is understood as omitted input code, as the prompt intends.

The early declaration tells the compiler that the call returns double. Removing it means a modern C compiler encounters an undeclared function call; older implicit-int conventions instead assume int, which conflicts with the later double definition. A diagnostic is required, and ordinary compiler modes reject the conflicting types, making D the conventional choice. The standard does not mandate the user-interface label warning versus error, so that distinction remains qualified.

Original paper, page 4