title: Difference between styles of iterating over vectors and other stl containers
body: <p>Suppose there is an stl container, for the sake of simplicity I am going to use a vector declared as</p>
  
  <p>After getting the answer I realized that it was because I wasn't actually iterating over <code>int</code> but a custom data structure template <code>T</code>, just making edits so someone in the future might find it easier to understand. </p>
  
  <p><code>std::vector &lt;T&gt; vec;</code></p>
  
  <p>Now there are two common methods to iterate over it.</p>
  
  <p>1.</p>
  
  <pre><code>for(std::vector&lt;T&gt;::iterator it = vec.begin(); it != vec.end(); ++it)
  {
      /* std::cout &lt;&lt; *it; ... */
  }
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>for(T t: vec)
  {
      /* std::cout &lt;&lt; t; ... */
  }
  </code></pre>
  
  <p>Now I always assumed that both these methods were more or less same under the hood and were supposed to have similar runtime, but recently in a competition on hackerearth the second one (My usual Goto) gave TLE on the last test case and just by switching to first method I managed to get all the cases passed, did I miss something that differentiates between them or it was just a coincidence (Since actual difference between their runtime was minute, just on different side of the limit). I couldn't find anything, so if you have any links or Insights please share.</p>