title: Where are pointers in C++ stored, on the stack or in the heap?
body: <p>I am trying to understand the difference between the <strong>stack</strong> and <strong>heap</strong> memory, and <a href="https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap">this question</a> on SO as well as <a href="http://www.programmerinterview.com/index.php/data-structures/difference-between-stack-and-heap/" rel="noreferrer">this explanation</a> did a pretty good job explaining the basics. </p>
  
  <p>In the second explanation however, I came across an example to which I have a specific question, the example is this:</p>
  
  <p><img src="https://i.stack.imgur.com/FzluQ.png" alt="heap allocation example"></p>
  
  <p>It is explained that the object <code>m</code> is allocated on the <strong>heap</strong>, I am just wondering if this is the full story. According to my understanding, the object itself indeed is allocated on the <strong>heap</strong> as the <code>new</code> keyword has been used for its instantiation.</p>
  
  <p>However, isn't it that <strong>the pointer to object <code>m</code> is on the same time allocated on the stack</strong>? Otherwise, how would the object itself, which of course is sitting in the <strong>heap</strong> be accessed. I feel like for the sake of completeness, this should have been mentioned in this tutorial, leaving it out causes a bit of confusion to me, so I hope someone can clear this up and tell me that I am right with my understanding that this example should have basically two statements that would have to say:</p>
  
  <p><strong>1. a pointer to object <code>m</code> has been allocated on the stack</strong></p>
  
  <p><strong>2. the object <code>m</code> itself (so the data that it carries, as well as access to its methods) has been allocated on the heap</strong></p>