title: How Iterators find the next address in a linked list
body: <p>I'm coming from a C background. </p>
  
  <p>When iterating through a container such as a vector or deque which contains elements in contiguous memory, it's easy to understand that by incrementing the iterator to point to the next element in the vector, such as in the loop below, it may just increase the address of the iterator by the size of the element in the vector, in this case int.</p>
  
  <pre><code>vector&lt;int&gt; vec;
  vector&lt;int&gt;::iterator it;
  
  for (it = vec.begin; it != vec.end(); it++)
  {
      // do something on each element
  
  }
  </code></pre>
  
  <p>The benefits i believe of using iterators is that we can decouple the algorithm code from the actual container type, so if we decide later to use a list instead of a vector, we can use the same iteration code as above on the list.</p>
  
  <p>It is possible to iterate through a list in the exact same way, but a list will have elements not in contiguous memory locations, so how does the iterator increment and find the correct address of the next element?  </p>
  
  <p>My understanding from implementing linked lists in C is that we would check the pointer in the node, possibly called "next" which points to the next node in the list.   </p>
  
  <p>Is this exactly what's happening here in C++ behind the scenes when using list iterators? Therefore , when an iterator is pointing to a list element, in order to point to the next element, the compiler will generate completely different code to that of pointing to the next element in a vector? Thanks in advance.  </p>