<p>(I'm using Visual C++ 2008) I've always heard that main() is <em>required</em> to return an integer, but here I didn't put in <code>return 0;</code> and and it compiled with 0 errors and 0 warnings!  In the debug window it says the program has exited with code 0.  If this function is named anything other than main(), the compiler complains saying 'blah' must return a value.  Sticking a <code>return;</code> also causes the error to appear.  But leaving it out completely, it compiles just fine.</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

int main()
{
    cout &lt;&lt; "Hey look I'm supposed to return an int but I'm not gonna!\n";
}
</code></pre>

<p>Could this be a bug in VC++?</p>

[{'answer_id': 22251, 'author': 'bradtgmurray', 'author_id': 1546, 'author_profile': 'https://Stackoverflow.com/users/1546', 'pm_score': 2, 'selected': False, 'text': "<p>I'm pretty sure VC++ just inserts a return 0 if you don't include one in main functions. The same thing can happen with functions too, but in those cases at least you'll get a warning.</p>\n"}, {'answer_id': 22253, 'author': 'On Freund', 'author_id': 2150, 'author_profile': 'https://Stackoverflow.com/users/2150', 'pm_score': 4, 'selected': False, 'text': "<p>This is part of the C++ language standard. An implicit return 0 is generated for you if there's no explicit return statement in main.</p>\n"}, {'answer_id': 22262, 'author': 'sparkes', 'author_id': 269, 'author_profile': 'https://Stackoverflow.com/users/269', 'pm_score': 7, 'selected': True, 'text': '<blockquote>\n<h1>3.6.1 Main function</h1>\n<p>....</p>\n<p>2 An implementation shall not predefine the <code>main</code> function. This function shall not be overloaded. It shall have a return type of type <code>int</code>, but otherwise its type is implementation-defined. All implementations shall allow both of the following definitions of main:</p>\n<pre><code>int main() { /* ... */ }\n</code></pre>\n<p>and</p>\n<pre><code>int main(int argc, char* argv[]) {\n/* ... */\n}\n</code></pre>\n<p>.... and it continues to add ...</p>\n<p>5 A <code>return</code> statement in <code>main</code> has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling <code>exit</code> with the return value as the argument. <strong>If control reaches the end of <code>main</code> without encountering a return statement, the effect is that of executing return 0</strong>;</p>\n</blockquote>\n<p>attempting to find an online copy of the C++ standard so I could quote this passage <a href="http://zamanbakshifirst.blogspot.com/2006/11/c-c-main-should-return-void.html" rel="noreferrer">I found a blog post that quotes all the right bits better than I could.</a></p>\n'}, {'answer_id': 3492633, 'author': 'Chubsdad', 'author_id': 418110, 'author_profile': 'https://Stackoverflow.com/users/418110', 'pm_score': 2, 'selected': False, 'text': '<p>Section 6.6.3/2 states- "Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function.".</p>\n\n<p>An example is the code below which at best gives warning on VS 2010/g++</p>\n\n<pre><code>int f(){\n   if(0){\n      if(1)\n         return true;\n   }\n}\n\nint main(){\n   f();\n}\n</code></pre>\n\n<p>So the whole point is that \'main\' is special as the previous responses have pointed out.</p>\n'}]
['https://Stackoverflow.com/questions/22239', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2222/']