return in function

When do you not have to use the keyword return when you define a function???
When it doesn't return anything (void).
lol, thanks :)
And in int main()

If you omit it, it assumes you meant return 0;

1
2
3
4
5
6
7
#include <iostream>
using namespace std;

int main()
{
    cout << "Hi!\n";
}

Last edited on
And in the contrary situation, even when the return type is void, the keyword return may still be used. It's particularly useful to terminate processing before reaching the closing brace of the function.
Topic archived. No new replies allowed.