title: Unexpected static counter variable behaviour
body: <p>Lately I tried getting my head around the static keyword and here I attempt to simply use the static keyword for a variable declaration within a function. Like so:</p>
  
  <pre><code>void counter()                                                                                        
  {                                                                                                     
      static int counter = 0; //should be initialized only once and once only                           
      counter++; //increment for every call of this function                                            
  }
  </code></pre>
  
  <p>I understand that due to the variable being static, it will live outside the function and therefore from wherever I decide to print out counter, it should give me the number of times the function <code>counter()</code> was called. So I did a simple test as shown:</p>
  
  <pre><code>int main()                                                                                            
  {                                                                                                     
      for(unsigned int i = 0; i &lt; 10; i++){                                                             
          counter();                                                                                    
      }                                                                                                 
      std::cout &lt;&lt; counter &lt;&lt; std::endl;                                                                
  
      return 0;                                                                                         
  }
  </code></pre>
  
  <p>From this test I expected to get number 10... but instead the number of counts the code returned was 1. </p>
  
  <p>Please, what am I missing here?</p>
  
  <p>I found other submissions to "similar" issues such as this one:
  <a href="https://stackoverflow.com/questions/10881410/static-counter-in-c">static counter in c++</a>
  But they mostly revolve around the static keyword being used in classes.</p>