Why does the following program works fine?
int main()
{
int x;
x = foo();
printf(\"%d\",x);
getchar();
return 0;
}
int foo()
{
return 2;
Anything called as a function C is by default of type int, with no parameters (such as in your first case). If the compiler then finds a function which complies, there is no error.
In the second case, the compiler compiles main() thinking the function is int, but then finds it's not true, and reports an error!
COMMENT: Jonathan Leffler commented:
Only in C89/C90. Not in C99; not in C11. Of course, some vendors still only implement C89; a notable example is Microsoft!