title: Can you call a void function of array when it is in between two loops?
body: <p>I wrote code which take size of an array and enter the elements of an array and then cyclically rotate an array.
  INPUT : 1 2 3 4 5 //elements of an array 
  Correct Output: 5 1 2 3 4</p>
  
  <p>//I made rotate function for the program but when i called it ,the program run but didnt show me the correct answer instead when i wrote that code in the main function like i've done below it worked out!!! WHY?</p>
  
  <pre><code>   #include&lt;iostream&gt;
     using namespace std;
     void rotate(int arr[],int n) 
     {                                
       int x=arr[n-1],i;
       for(i=n-1;i&gt;0;i--)
       {arr[i]=arr[i-1];}
       arr[0]=arr[x];}
   int main()           
   {
    int t;
    cin&gt;&gt;t; //for test case(How many test cases i have to perform) 
    while(t--)
  {
      int n,i,arr[i]; 
      cin&gt;&gt;n;  //size of an array 
      cout&lt;&lt;"Enter the given array :"&lt;&lt;endl;
      for(i=0;i&lt;n;i++)
      {cin&gt;&gt;arr[i];}  //Enter elements of an array 
      cout&lt;&lt;"THe given array is :"&lt;&lt;endl;
      for(int i=0;i&lt;n;i++) 
      {cout&lt;&lt;arr[i]&lt;&lt;" ";} //print the elements of an array
  </code></pre>
  
  <p>//Writing Whole ROTATE FUNCTION in the MAIN</p>
  
  <pre><code>    int x=arr[n-1],i; 
      for(i=n-1;i&gt;0;i--)
      {arr[i]=arr[i-1];}
      arr[0]=arr[x];//when you didnt make  a function to rotate an array its compiled and  showing 
                   //correct results. why?    
      cout&lt;&lt;"The Rotated Array is :"&lt;&lt;endl;
      for(int i=0;i&lt;n;i++)
      {cout&lt;&lt;arr[i]&lt;&lt;" "; }
      cout&lt;&lt;endl;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>When i called the rotate function in the main function it showed me following incorrect Output:
  Output : 0 1 2 3 4.
  FOllowing way the answer was incorrect:
      when i call :
           <strong>rotate(arr,n)</strong>
  But When i didnt call a rotate function.Instead i wrote the whole function in the main,The output was corrected like i have shown you in the above code.</p>