I know there are two types of functions: void
and the ones that return something (int, double, etc). But what if a function is declared without any return statements? Is it considered to be a void
function? For example,
myFunction(int value){
.......
}
A function declared without any return type is considered returning an int
. This is an ancient rule going back to the original K&R C, left in the language for backward compatibility.
Integer promotions and conversion of float
arguments to double
s are done for functions without prior definition or forward declaration for the same reason - backward compatibility with really old code.
It is needless to say that relying on these rules for new development is a very bad practice. One should always declare return type explicitly, and forward-declare or define all functions before calling them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With