title: vectors in range based for loop
body: <p>I was testing vector to vector initialization, I used range based for loop it gives different output.</p>
  
  <p>with respect to Normal for loop.</p>
  
  <pre><code>vector&lt;int&gt; intVector;
  
  for(int i = 0; i &lt; 10; i++) {
      intVector.push_back(i + 1);
      cout &lt;&lt; intVector[i] &lt;&lt; endl;
  }
  
  cout &lt;&lt; "anotherVector" &lt;&lt; endl;
  
  vector&lt;int&gt; anotherVector(intVector);
  for(auto i : anotherVector)
      cout &lt;&lt; anotherVector[i] &lt;&lt; endl;
  //for(unsigned int i = 0; i &lt; anotherVector.size(); i++) {
  //    cout &lt;&lt; anotherVector[i] &lt;&lt; endl;
  //}
  </code></pre>
  
  <p>this range based for loop gives the output - Linux ubuntu</p>
  
  <p>Output</p>
  
  <pre><code>STLTest Cunstructor Called.
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  anotherVector
  2
  3
  4
  5
  6
  7
  8
  9
  10
  81
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>vector&lt;int&gt; intVector;
  
  for(int i = 0; i &lt; 10; i++) {
      intVector.push_back(i + 1);
      cout &lt;&lt; intVector[i] &lt;&lt; endl;
  }
  
  cout &lt;&lt; "anotherVector" &lt;&lt; endl;
  
  vector&lt;int&gt; anotherVector(intVector);
  //for(auto i : anotherVector)
  //    cout &lt;&lt; anotherVector[i] &lt;&lt; endl;
  for(unsigned int i = 0; i &lt; anotherVector.size(); i++) {
      cout &lt;&lt; anotherVector[i] &lt;&lt; endl;
  }
  </code></pre>
  
  <p>This gives different output.</p>
  
  <p>output</p>
  
  <pre><code>STLTest Cunstructor Called.
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  anotherVector
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  </code></pre>
  
  <p>why both for loop acting differently?</p>