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 is deleted, the above code will show:
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:
- When the compiler encounters the call
db = foo(da);insidemain(), it implicitly declaresfooas:int foo(); - Later in the file, the compiler encounters the actual definition of
foo:double foo (double a) { ... } - This creates a conflicting type specification for the function
foo(returningdoubleinstead of the implicitly assumedint).
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.
