can I write c++ main function without return integer value? I am using visual studio 2010.
#include <iostream>
using namespace std;
int main()
{
cout <<"In main function" << endl;
//return 0;
} `
can I write c++ main function without return integer value? I am using visual studio 2010.
#include <iostream>
using namespace std;
int main()
{
cout <<"In main function" << endl;
//return 0;
} `
Yes, since the release of C99, you can skip the return value of main()
.
Let's look at C++11
3.6.1
A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std::exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing
return 0;
According to the C++ Standard (3.6.1 Main function)
5 A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std::exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing
return 0;
Thus the shortest C++ program is
int main() {}
With the VS2010 compiler, you actually can declare it as void main()
if you're not interested in returning a value.
Though this isn't a C++ standard compliant feature.