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

suggest change

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.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents