title: C++ program behavior on pointers to integer array
body: <blockquote>
  <p>Can anyone please explain why the loop only execute once!!</p>
  </blockquote>
  <p>The for loop executes once and never reaches end of the programm
  and if you've got some time to review my mistakes then please point out mistakes because i know this is not how it is done!!</p>
  <pre><code>using namespace std;
  #include&lt;iostream&gt;
  
  int* rotate(int* ar,int d,int n)
  {
      int tmp[n];
      d = d%n;
  
      for (int i = 0; i &lt; n; ++i)
      {
          tmp[i] = ar[(i+d)%n];
      }
      free(ar);
      return tmp;
  }
  
  
  int main(int argc, char const *argv[])
  {
      int arr[] = {1,2,3,4,5};
      int *a;
      int n = sizeof(arr)/sizeof(arr[0]);
      a = rotate(arr,4,n);
      cout&lt;&lt;endl;
  
      for (int i = 0; i &lt; n; ++i)
      {
           cout&lt;&lt;i&lt;&lt;endl;
           cout&lt;&lt;a[i]&lt;&lt;endl;
      }
      cout&lt;&lt;&quot;End&quot;;
      return 0;
  }
  </code></pre>