return Statement in Program Termination (C++)
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at return Statement in Program Termination (C++).
Issuing a return statement from main is functionally equivalent to calling the exit function. Consider the following example:
// return_statement.cpp
#include <stdlib.h>
int main()
{
exit( 3 );
return 3;
}
The exit and return statements in the preceding example are functionally identical. However, C++ requires that functions that have return types other than void return a value. The return statement allows you to return a value from main.
Show: