I executed the code in code:blocks
I execute the following code:
//No prototype declaration for the function foo()
int da, db; //int instead of double
da = 20; //initialization
db = foo(da); //implicit declaration of function foo()
int foo(int a)
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.
Please correct me if what I am assuming is wrong.