When you don't provide a function prototype before it is called, the compiler assumes that the function is defined somewhere which will be linked against its definition during the linking phase. The default return type is assumed to be int
and nothing is assumed about the function parameter. This is called implicit declaration. This means that the assumed function signature here is
int sum();
Here, the empty parameter list means the function sum
takes a fixed but unknown number of arguments all of which are of unknown types. It is different from the function declaration
int sum(void);
However, in C++
, the above two declarations are exactly the same. If your function has a return type other than int
, then the assumed function signature won't match and this will result in compile error. In fact, it's an error in C99
and C11
. You should always provide function prototype before it is called.