Skip to content
Official PYQ · 2005

GATE CS 2005 Q32 — Programming in C

Explain with AI

Consider the following C program:

double foo (double);		/* Line 1 */
int main() {
    double da, db;
    //input da
    db = foo(da);
}
double foo (double a) {
    return a;
}

The above code compiled without any error or warning. If Line 11 is deleted, the above code will show:

Choose one option
View worked solution

Answer: D

In C (specifically C89/C90 standards, which are standard for GATE), if a function is called before it is declared or defined, the compiler assumes an implicit declaration of the function with a return type of int.

If Line 1 (the prototype double foo (double);) is deleted:

  1. When the compiler encounters the call db = foo(da); inside main(), it implicitly declares foo as:
    int foo();
  2. Later in the file, the compiler encounters the actual definition of foo:
    double foo (double a) { ... }
  3. This creates a conflicting type specification for the function foo (returning double instead of the implicitly assumed int).

A conflicting redeclaration of a function within the same translation unit is a violation of C syntax and results in a compiler error.

Therefore, the correct option is D.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Programming in C questions