title: Delete pointer after return statement
body: <p>I ran into the following problem: I want to return a Y-coordinate, and after I returned it, it needs to be deleted. </p>
  
  <p>Is there a way to do this, because I think I'm missing some major things here.</p>
  
  <pre><code>void setY(int y)
      {
          this-&gt;y = new(int); //pointing to new address
          *this-&gt;y = y; //change value of pointer
      }
  
      int getY()
      {
          return *y; //give the coordinate
          delete y; //what I want
          *y = NULL; //what I want
      }
  </code></pre>
  
  <p>Thank you in advance. If the question is not well described, please let me know.</p>