title: Does int main() need a declaration on C++?
body: <p>I was taught that functions need declarations to be called. To illustrate, the following example would give me an error as there is no declaration for the function <code>sum</code>:</p>
  <pre><code>#include &lt;iostream&gt;
  
  int main() {
    std::cout &lt;&lt; &quot;The result is &quot; &lt;&lt; sum(1, 2);
    return 0;
  }
  
  int sum(int x, int y) {
    return x + y;
  }
  
  // main.cpp:4:36: error: use of undeclared identifier 'sum'
  //  std::cout &lt;&lt; &quot;The result is &quot; &lt;&lt; sum(1, 2);
  //                                   ^
  // 1 error generated.
  </code></pre>
  <p>To fix this, I'd add the declaration:</p>
  <pre><code>#include &lt;iostream&gt;
  
  int sum(int x, int y); // declaration
  
  int main() {
    std::cout &lt;&lt; &quot;The result is &quot; &lt;&lt; sum(1, 2);
    return 0;
  }
  
  int sum(int x, int y) {
    return x + y;
  }
  </code></pre>
  <p>Why the <code>main</code> function doesn't need the declaration, as other functions like <code>sum</code> need?</p>