C++ std::list segmentation fault : <p>I got a segmentation fault (core dumped) while runing my programm. The first version runs perfectly but i need the list as a pointer but then the code doesn't work anymore see second code. What am i doing wrong?</p>

<p>Runing version:</p>

<p></p>

<pre><code>int main(int argc, char *argv[]) {

  std::list&lt;int&gt; TestList;
  for (int i = 0; i &lt; 10; ++i) {
    TestList.push_back(i);
  }

  for (std::list&lt;int&gt;::const_iterator iterator = TestList.begin(), end = TestList.end(); iterator != end; ++iterator) {
    std::cout &lt;&lt; *iterator &lt;&lt; std::endl;
  }  

  return 0;
}
</code></pre>

<p></p>

<p>Not runing version:</p>

<p></p>

<pre><code>int main(int argc, char *argv[]) {

      std::list&lt;int&gt; *TestList;
      for (int i = 0; i &lt; 10; ++i) {
        TestList-&gt;push_back(i);
      }

      for (std::list&lt;int&gt;::const_iterator iterator = TestList-&gt;begin(), end = TestList-&gt;end(); iterator != end; ++iterator) {
        std::cout &lt;&lt; *iterator &lt;&lt; std::endl;
      }  

  return 0;
}    
</code></pre>

<p></p>
