title: Why cpp in code blocks assign same address to variable declared in a function even if it called many times?
body: <p>I am running the following program in code blocks with GNU GCC as compiler on windows platform. Here in this program I want to check whether integer declared in function changes memory location. I know due to compiler optimization it may happen sometime that it will keep same address for variable even if it declared multiple times. But I am calling it million times then also it takes same address. I also tried it with volatile keyword even with volatile keyword it shows same output.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int* test (int a, int b)
  {
     int c=0;
     c=c+a+b;
     return &amp;c;
  }
  
  int main()
  {
    int* pre;
    pre = test(5,9);
    int i=0;
    for( i=0;i&lt;1000000;i++)
    {
      int* cur = test(i,i+6);
      if(cur!=pre)
      {
          cout&lt;&lt;"wrong";
      }
  }
  cout&lt;&lt;i;
   return 0;
  }
  </code></pre>