title: what list iterator exactly is in cplusplus stl
body: <p>ENV: windows 7 x64, Visual Studio Community 2015</p>
  
  <p>I am a newbie of cplusplus and stl. I am trying to find what a list iterator exactly is. I write two piece of codes, and iterator in both of them seems have a different value with the address of the list element. It looks wired that it still can get the value of element using operator *. Any references, ideas about this? Thanks for your time.</p>
  
  <p><strong>Codes with struct list:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;cstdio&gt;
  
  typedef struct st
  {
      int m;
      int n;
  }st_t;
  
  int main (int argc, char *argv[])
  {
      int *_i1, *_i2;
      st_t *pST;
      std::list&lt;st_t&gt; stList;
      std::list&lt;st_t&gt;::iterator iterSTList;
      st_t varST;
      varST.m = 1;
      varST.n = 10;
      stList.push_back(varST);
      varST.m = 2;
      varST.n = 20;
      stList.push_back(varST);
  
      for (iterSTList=stList.begin(); iterSTList!=stList.end(); iterSTList++)
      {
          pST = &amp;(*iterSTList);
          std::cout &lt;&lt; " pST-&gt;m " &lt;&lt; pST-&gt;m &lt;&lt; std::endl
                    &lt;&lt; " pST-&gt;n " &lt;&lt; pST-&gt;n &lt;&lt; std::endl
                    &lt;&lt; " (*pST).m " &lt;&lt; (*pST).m &lt;&lt; std::endl
                    &lt;&lt; " (*pST).n " &lt;&lt; (*pST).n &lt;&lt; std::endl
                    &lt;&lt; " pST " &lt;&lt; pST &lt;&lt; std::endl
                    &lt;&lt; " &amp;(*iterSTList) " &lt;&lt; &amp;(*iterSTList) &lt;&lt; std::endl;
  
          std::printf("iterSTList %X \n", iterSTList);
  
          _i1 = &amp;(iterSTList-&gt;m);
          _i2 = &amp;(iterSTList-&gt;n);     
          std::cout &lt;&lt; " _i1 " &lt;&lt; _i1  &lt;&lt; " iterSTList-&gt;m " &lt;&lt; iterSTList-&gt;m &lt;&lt; std::endl
                    &lt;&lt; " *_i1 " &lt;&lt; *_i1  &lt;&lt; " (*iterSTList).m " &lt;&lt; (*iterSTList).m &lt;&lt; std::endl
                    &lt;&lt; " _i2 " &lt;&lt; _i2  &lt;&lt; " iterSTList-&gt;n " &lt;&lt; iterSTList-&gt;n &lt;&lt; std::endl
                    &lt;&lt; " *_i2 " &lt;&lt; *_i2  &lt;&lt; " (*iterSTList).n " &lt;&lt; (*iterSTList).n &lt;&lt; std::endl;
  
      }
  
      return 0;
  }
  </code></pre>
  
  <p><strong>result</strong></p>
  
  <blockquote>
    <p>pST->m 1 <BR> pST->n 10 <BR> (*pST).m 1 <BR> (*pST).n 10 <BR> pST 00323F90 <BR> 
    &amp;(*iterSTList) 00323F90 <BR> iterSTList 323960 <BR> _i1 00323F90 iterSTList->m
    1 <BR> *_i1 1 (*iterSTList).m 1 <BR> _i2 00323F94 iterSTList->n 10 <BR> *_i2 10
    (*iterSTList).n 10 <BR> pST->m 2 <BR> pST->n 20 <BR> (*pST).m 2 <BR> (*pST).n 20 <BR> pST
    00323FD0 <BR> &amp;(*iterSTList) 00323FD0 <BR> iterSTList 323960 <BR> _i1 00323FD0
    iterSTList->m 2 <BR> *_i1 2 (*iterSTList).m 2 <BR> _i2 00323FD4 iterSTList->n
    20 <BR> *_i2 20 (*iterSTList).n 20</p>
  </blockquote>
  
  <p>See. the value of iterSTList is different with &amp;(*iterSTList), but iterSTList can get the element value like a pointer</p>
  
  <p><em>Codes without struct:</em></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;cstdio&gt;
  
  int main (int argc, char *argv[])
  {
      int *p;
      std::list&lt;int&gt; iList;
      std::list&lt;int&gt;::iterator iter;
      int m;
      m = 1;
      iList.push_back(m);
      m = 2;
      iList.push_back(m);
  
      for (iter=iList.begin(); iter!=iList.end(); iter++)
      {
          p = &amp;(*iter);
          std::cout &lt;&lt; " p " &lt;&lt; p &lt;&lt; " *p " &lt;&lt; *p &lt;&lt; std::endl
                    &lt;&lt; " &amp;(*iter) " &lt;&lt; &amp;(*iter) &lt;&lt; " *iter " &lt;&lt; *iter &lt;&lt; std::endl;
  
          std::printf("iter %X \n", iter);
  
      }
  
      return 0;
  }
  </code></pre>
  
  <p><strong>result</strong></p>
  
  <blockquote>
    <p>p 007039D8 *p 1   <BR>
     &amp;(*iter) 007039D8  *iter 1  <BR>
     iter 703998   <BR>
     p 00703A10  *p 2   <BR>
     &amp;(*iter) 00703A10  *iter 2  <BR>
     iter 703998 <BR></p>
  </blockquote>
  
  <p>same thing. the value of iter is different with &amp;(*iter) and p. But *iter and *p get the same value.</p>
  
  <p>Any thing wrong with my code? iter is an iterator, of course. Does it can be treated as a pointer sometimes? when? Thanks.</p>
  
  <p>After compiling on VS 2015:</p>
  
  <pre><code>Severity    Code    Description Project File    Line    Suppression State
  Warning C4477   'printf' : format string '%X' requires an argument of type 'unsigned int', but variadic argument 1 has type 'std::_List_iterator&lt;std::_List_val&lt;std::_List_simple_types&lt;st&gt;&gt;&gt;'  tlist2  c:\users\cnpc\documents\visual studio 2015\projects\tlist2\tlist2\source.cpp    35  
  </code></pre>