title: Recursive power function in C++
body: <p>I'm having some trouble with this function. The function takes a and computes it to the power of b recursively. My compiler gives me a segmentation error when I compile this, which I'm not sure how to fix. Can anyone help?</p>
  <pre><code>/****   Recursive power function   &gt; Computes a^b, where b can be positive or negative*****/
          int recPower(double a, int b)
          {   
              if (b == 0)
              {
                  return 1;
              }
              else
              {
                  return (a *recPower(a, b-1));
              }
            }
  
  /* Computes a^b (power function) */    
  cout &lt;&lt; &quot;POWER&quot; &lt;&lt; endl;    
  cout &lt;&lt; &quot;----------&quot; &lt;&lt; endl;    
  int a = 2, b = -3;    
  cout &lt;&lt; a &lt;&lt; &quot;^&quot; &lt;&lt; b &lt;&lt; &quot; = &quot;;    
  cout &lt;&lt; recPower(a, b) &lt;&lt; endl;    
  cout &lt;&lt; endl;    
  </code></pre>