title: Variable creation on heap or stack in C++
body: <p><code>Circle</code> is a class, with public method <code>GetDiameter()</code>.
  What is the difference between the following 2 sets of code?</p>
  
  <p><strong>Qn1:</strong> Does <strong>Method 1</strong> allocates memory for <code>c</code> on <strong>stack</strong> (hence no need free memory), while <strong>Method 2</strong> allocates memory for <code>c</code> on <strong>heap</strong> (need manually free memory)?</p>
  
  <p><strong>Qn2:</strong> When should we use Method 1 or Method 2?</p>
  
  <p><strong>Method 1:</strong></p>
  
  <pre><code>void Init()
  {
   Circle c;
   c.GetDiameter();
  
   return;
  }
  </code></pre>
  
  <p><strong>Method 2:</strong></p>
  
  <pre><code>void Init()
  {
   Circle *c = new Circle();
   c-&gt;GetDiameter();
  
   return;
  }
  </code></pre>