return

suggest change

Returns control from a function to its caller.

If return has an operand, the operand is converted to the function’s return type, and the converted value is returned to the caller.

int f() {
    return 42;
}
int x = f(); // x is 42
int g() {
    return 3.14;
}
int y = g(); // y is 3

If return does not have an operand, the function must have void return type. As a special case, a void-returning function can also return an expression if the expression has type void.

void f(int x) {
    if (x < 0) return;
    std::cout << sqrt(x);
}
int g() { return 42; }
void h() {
    return f(); // calls f, then returns
    return g(); // ill-formed
}

When main returns, std::exit is implicitly called with the return value, and the value is thus returned to the execution environment. (However, returning from main destroys automatic local variables, while calling std::exit directly does not.)

int main(int argc, char** argv) {
    if (argc < 2) {
        std::cout << "Missing argument\n";
        return EXIT_FAILURE; // equivalent to: exit(EXIT_FAILURE);
    }
}

Feedback about page:

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


Flow control:
* if
* else
* case
* switch
* catch
* throw
* try
* goto
* return

Table Of Contents
8 Arrays
9 Flow control
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype