According to this link, if prototype is not declared before using a function. compiler guesses it based on type of parameters passed to it.

In this case parameters passed are double so it will create the prototype accordingly and process it. Moreover if it finds one more declaration of same function and prototype guessed does not match with given definition, it gives error.

check the error in the above pic 'conflicting types for foo'. It assumes return type of foo to be int and two functions cannot have different prototype like here both are foo, both taking argument as double but return type is different.

In ANSI C (meaning C89 or C90), you do not have to declare a function prototype; however, it is a best practice to use them. The only reason the standard allows you to not use them is for backward compatibility with very old code.

If you do not have a prototype, and you call a function, the compiler will infer a prototype from the parameters you pass to the function. If you declare the function later in the same compilation unit, you'll get a compile error if the function's signature is different from what the compiler guessed.

Worse, if the function is in another compilation unit, there's no way to get a compilation error, since without a a prototype there's no way to check. In that case, if the compiler gets it wrong, you could get undefined behavior if the function call pushes different types on the stack than the function expects.

Convention is to always declare a prototype in a header file that has the same name as the source file containing the function.

I think
" C compiler assumes it to return "int" but here foo is returning "double" and hence the compiler will throw type mis-match error. "
line not correct in answer.
Where type mismatch has occurred?

@tusharp so ans must be compiler error due to type mismatch due to backward compatibility(implicit declaration ,that return type of function is int) in this ques ?? and warning when void is used ,am i correct??

Above code will execute successfully even without warnings. The reason might be compiler implicitly assumes that the function foo has a return type of int and also at the end when it sees the function as what he assumes there will be no problem and therefore code executes correctly.

What I also observe is you have to make code:blocks to follow c99 standard. and when I set it and again execute code:

Compiler produces warning: implicit declaration of function 'foo'

but the code executes successfully and prints 20 as output.

but in the question, without a prototype as compiler assumes that foo() return int but as it goes it sees at the end function returns double type. therefore returns an error. therefore option (D) is correct and option (c) is not correct as it says some compiler-warning and not error.

In c programming the function definition can be done anywhere , after the main or before the main . I think there is no problem.(Plz check the code in gcc compilers)

CODE 1

double foo (double); /* Line 1 */
int main() {

double da, db;
//input da

db = foo(da);

}

double foo (double a) {
return a;
}

CODE 2

double foo (double); /* Line 1 */
double foo (double a) {
return a;
}

int main() {

double da, db;
//input da

db = foo(da);

}

You can see the difference as in CODE 1 I have written the function definition just above the main and in CODE 2 I have written function definition just after the main function . There is no problem with these codes.

Coming to function prototype ------

Positioning of function prototype -

If function definition is written after main then and then only we write prototype declaration in global declaration section

If function definition is written above the main function then ,no need to write prototype declaration

THAT I KNOW. You are right. I was confused about the point that if we write the function definition after calling the function, without even declaring the function or its prototype will it give compiler error or not???

Because i think C compiler will assume the datatypes of parameters from the call itself but the return type need to be specified.