title: Function returning static variable C++
body: <p>I fail to understand why the following program wrong:</p>
  
  <pre><code> int&amp; getID(){
     static int r = 0;
     return r++;
   }
  </code></pre>
  
  <p>main:</p>
  
  <pre><code> int main(){
     int a = getID();
     std::cout &lt;&lt; "a=" &lt;&lt; a &lt;&lt; std::endl;
     return 0;
   }
  </code></pre>
  
  <p>Why returning a static variable as described creates problems and not returning 
  the wanted value?</p>