title: On local and global static variables in C++
body: <p>C++ Primer says</p>
  
  <blockquote>
    <p>Each local static variable is initialized before the first time
    execution passes through the object's definition. Local statics are
    not destroyed when a function ends; they are destroyed when program
    terminates.</p>
  </blockquote>
  
  <p><strong>Are local static variables any different from global static variables? Other then the location where they are declared, what else is different?</strong></p>
  
  <pre><code>void foo () {   
      static int x = 0;
      ++x;
  
      cout &lt;&lt; x &lt;&lt; endl;
  }
  
  int main (int argc, char const *argv[]) {
      foo();  // 1
      foo();  // 2
      foo();  // 3
      return 0;
  }
  </code></pre>
  
  <p>compare with</p>
  
  <pre><code>static int x = 0;
  
  void foo () {   
      ++x;
  
      cout &lt;&lt; x &lt;&lt; endl;
  }
  
  int main (int argc, char const *argv[]) {
      foo();  // 1
      foo();  // 2
      foo();  // 3
      return 0;
  }
  </code></pre>