title: Pointers created on stack get destroyed? (diagram included) :- )
body: <p>If I create a buffer of pixels on the heap 6 by 10 ....</p>
  
  <p>int *p_buffer = new int[6 * 10]</p>
  
  <pre><code>p_buffer---
            |
            |
            V
            * * * * * * * * * *
            * * * * * * * * * *
            * * * * * * * * * *
            * * * * * * * * * *
            * * * * * * * * * *
            * * * * * * * * * *
  </code></pre>
  
  <p>Then in a method I create 6 pointers but I don't define them as "new", I understand this means they are stored on the stack.  I create an array of pointers like so:</p>
  
  <pre><code>int *p_row[6];
  </code></pre>
  
  <p>Then I manually place each p_row pointer at the start of each row, like so:</p>
  
  <pre><code>for (int i = 0; i &lt; 6; i++)
      {
       p_row[i] = p_buffer + (10 * i);
      }
  </code></pre>
  
  <p>So now we have:</p>
  
  <pre><code> p_buffer---
             |
             |
             V
  p_row[0]--&gt;* * * * * * * * * *
  p_row[1]--&gt;* * * * * * * * * *
  p_row[2]--&gt;* * * * * * * * * *
  p_row[3]--&gt;* * * * * * * * * *
  p_row[4]--&gt;* * * * * * * * * *
  p_row[5]--&gt;* * * * * * * * * *
  </code></pre>
  
  <p>I'm wondering, if after doing this the program leaves this function and goes back to main(), whether I can do something like:</p>
  
  <pre><code>p_row[0] = (set my RGB colours);
  </code></pre>
  
  <p>I've learned that things created in a function (local scope) are destroyed if created on the stack (without allocating or using 'new' keyword).</p>
  
  <p>After it leaves that function, are the pointers destroyed?  And can I reference them?</p>
  
  <p>I know this is an unorthodox way of referencing bytes, but the question is about the mechanics of pointers.  The whole buffer is allocated through p_buffer, which I intend to delete after the program quits.  I'm sorry if the answer if obvious.</p>
  
  <p>In addition, the array of pointers p_row[] will be a member of the class Screen, if this makes a difference.</p>