title: C/C++ header and implementation files: How do they work?
body: <p>This is <em>probably</em> a stupid question, but I've searched for quite a while now here and on the web and couldn't come up with a clear answer (did my due diligence googling).</p>
  
  <p>So I'm new to programming... My question is, how does the main function know about function definitions (implementations) in a different file?</p>
  
  <p>ex. Say I have 3 files</p>
  
  <ul>
  <li>main.cpp</li>
  <li>myfunction.cpp</li>
  <li>myfunction.hpp</li>
  </ul>
  
  <hr>
  
  <pre><code>//main.cpp
  
  #include "myfunction.hpp"
  int main() {
    int A = myfunction( 12 );
    ...
  }
  </code></pre>
  
  <p>-</p>
  
  <pre><code>//myfunction.cpp
  
  #include "myfunction.hpp"
  int myfunction( int x ) {
    return x * x;
  }
  </code></pre>
  
  <p>-</p>
  
  <pre><code>//myfunction.hpp
  
  int myfunction( int x );
  </code></pre>
  
  <p>-</p>
  
  <p>I get how the preprocessor includes the header code, but how do the header and main function even know the function definition exists, much less utilize it?</p>
  
  <p>I apologize if this isn't clear or I'm vastly mistaken about something, new here</p>