title: Returning a pointer of a local variable C++
body: <p>I need to create a function that returns a pointer to an int.</p>
  
  <p>Like so:</p>
  
  <pre><code>int * count()
  {
      int myInt = 5;
  
      int * const p = &amp;myInt;
  
      return p;
  }
  </code></pre>
  
  <p>Since a pointer is simply an address, and the variable myInt is destroyed after this function is called. How do I declare an int inside this method that will keep a place in the memory in order for me to access it later via the returned pointer?  I know I could declare the int globally outside of the function, but I want to declare it inside the function.</p>
  
  <p>Thanks in advance for any help!</p>