Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function without any return type

Tags:

c

function

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){
.......
}
like image 393
Mike Avatar asked Sep 14 '25 19:09

Mike


1 Answers

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 doubles 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.

like image 50
Sergey Kalinichenko Avatar answered Sep 16 '25 08:09

Sergey Kalinichenko