C++ No return statement for a function with a non-void return type


Example

Omitting the return statement in a function which is has a return type that is not void is undefined behavior.

int function() {  
    // Missing return statement
} 

int main() {
    function(); //Undefined Behavior
}

Most modern day compilers emit a warning at compile time for this kind of undefined behavior.


Note: main is the only exception to the rule. If main doesn't have a return statement, the compiler automatically inserts return 0; for you, so it can be safely left out.