title: Affect of tem assignment in last for loop
body: <p>In the last "for" loop of below code, I expected same output for the assignment of "tem" above the last "for " loop as well as within the last "for" loop. But the outputs are different. Could anyone explain why?</p>
  
  <p>I tried assigning the tem between while and for loop as well as within the last for loop.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;vector&gt;
  using namespace std;
  
  
    void temp(int a[][4],int m,int n,int k){
  
          int temp[m*n];
          int row=0,col=0;
          int *tem=temp;
          int r=m,l=n;
          int *start=temp;
  
   while(row&lt;m&amp;&amp;col&lt;n){
                        int *end=start;
  
     for(int i=row;i&lt;m;i++){
  
                       *tem=a[i][col];
                      tem++;
                      end++;
  
                      }col++;
      for(int i=col;i&lt;n;i++){
  
                       *tem=a[m-1][i];
                      tem++;
                      end++;
  
                            }m--;
  
      for(int i=m-1;i&gt;=row;i--){
  
                              *tem=a[i][n-1];
                                  tem++;
                                 end++;
                                }n--;
      for(int i=n-1;i&gt;=col;i--){
  
                            *tem=a[row][i];
                              tem++;
                              end++;
                              }row++;  
  
      if(end-start&gt;k){reverse(start,k,end-1);
  
                 start=end;
                      }}   
      for(int i=0;i&lt;r*l;i++){ 
  
                         tem=temp;
  
                      cout&lt;&lt;*tem&lt;&lt;" ";
                      tem++;
  
  
                  }
  
  
       }
     void reverse(int *start,int k,int *end){
                        int *s=start;
                        int *e=start+k-1;
      while(s&lt;e){ 
          int tem=*s;
          *s=*e;
           *e=tem;
          s++;e--;
          }
                          s=start+k; e=end;
      while(s&lt;e){
  
                            int tem=*s;
                             *s=*e;
                          s++;e--;
          }
                         s=start; e=end;
      while(s&lt;e){
                          int tem=*s;
                         *s=*e;
                         *e=tem;
                          s++;e--;
  
          }   
  
  
   }
  
  
  
      int main(){
  
   int b[][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};int j=0;
  
     temp(b,4,4,3);
  
  
  
     }
  </code></pre>
  
  <p>If the assignment of tem is inside 
  13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 
  I expected 
  13 14 15 16 12 8 4 3 2 1 5 9 7 6 10 11
  which is the output if i assign tem between while and for loop.</p>