title: With regard to memory allocation, how (or where) should I declare the following variables?
body: <p>I'm not sure whether it's appropriate to ask this here. I'm concerned about the memory allocation and I don't know where to read up on that.</p>
  
  <p>I'm debating with myself whether I should declare local variables per root-finding function, or just use global variables that each function can reuse per call. Please note that I don't plan on using recursion here. Just (do-)while (or for) loops only.</p>
  
  <p>I'd really appreciate it if I can get sufficient explanation too.</p>
  
  <pre><code>// [1]
  // global(?) variables
  // functions.cpp
  
  #include &lt;cmath&gt;
  #include "functions.h"
  
  using namespace std;
  
  double guess1;     // upper
  double guess2;     // lower
  double root;
  double prevGuess;
  double sigFigs;
  double minSigFigs;
  
  double newt_rhap(params)
  {
     // do stuff
  }
  double bisection(params)
  {
     // do stuff
  }
  </code></pre>
  
  <p>===============</p>
  
  <pre><code>// [2]
  // local variables
  // functions.cpp
  
  #include &lt;cmath&gt;
  #include "functions.h"
  
  using namespace std;
  
  
  double newt_rhap(x,y,z,f(),f_prime())
  {
     double guess = x;
     double sigFigs = y;
     double minSigFigs = z;
  
     // do stuff
  }
  double false_position(w,x,y,z,a())
  {
     double xr;
     double upper = w;
     double lower = x;
     double xprev;
     double fxr;
     double fxu;
     double fxl;
     double sigFigs = y;
     double minSigFigs = z;
  
     // do stuff
  }
  </code></pre>