title: Why create abc.h and abc.cpp file in a c++ program?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/333889/in-c-why-have-header-files-and-cpp-files">In C++ why have header files and cpp files?</a>  </p>
  </blockquote>
  
  
  
  <p>I was reading some KDE tutorials for creating basic plasma widgets and other QT stuff. One thing that I noticed is almost all the programs has a <code>.h</code> and <code>.cpp</code> with header file included in the cpp file.</p>
  
  <p>The basic thing that I get is to minimize the clutter in the file and make the code more readable.</p>
  
  <p>My question is what things should I put in a .h file and .cpp file writing a program  and how it is going to benefit me in improving my code.</p>
  
  <p>For example - I've created 3 files , add.h, add.cpp and pass.cpp - Now add.h has the function while other 2 have definition.</p>
  
  <p>Add.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int add (int x,int y);
  </code></pre>
  
  <p>Add.cpp</p>
  
  <pre><code>#include "add.h"
  
  int main() {
  
      add (int x, int y) {
  
      int z = x+y;
  
      cout&lt;&lt;"Add is "&lt;&lt;"\t"&lt;&lt;z;
  
      }
  return 0;
  }
  </code></pre>
  
  <p>Pass.cpp</p>
  
  <pre><code>#include "add.h"
  
  
  add (3,4);
  </code></pre>
  
  <p>However this doesn't work , judging from the answer here  <a href="https://stackoverflow.com/questions/333889/in-c-why-have-header-files-and-cpp-files">Why have header files and .cpp files in C++?</a></p>
  
  <p>contents of add.h are automatically copied yet I get several errors.</p>