title: Insertion sort mistake
body: <pre><code>int main(){
      int i,j,temp;
      int a[]={3,2,4,7,1};
      for(i=1;i&lt;5;i++){
          temp=a[i];
          for(j=i-1;j&gt;=0;j--){
              if(a[j]&gt;temp)
                  a[j+1]=a[j];
              else
                  break;
          }
         a[j+1]=temp;//if I replace this by a[i] I am getting wrong output.
      }
      for(i=0;i&lt;5;i++)
          printf("\n\n%d",a[i]);
      return 0;
  }
  </code></pre>
  
  <p>In the inner loop I am not changing the value of variable i. Then if I replace <code>a[j+1]=a[i]</code>, I am getting wrong output. Am I missing some important concept?</p>