title: Returning a malloc pointer
body: <p>Pretty basic question here, I'm a little unsure on the passing around of memory in C.</p>
  
  <p>If I have the following</p>
  
  <pre><code>CGPoint* tileForCoordinates (CGPoint position, short width, short height)
  {   
     CGPoint *tileCoordinate = (CGPoint*)malloc(sizeof(CGPoint));
     tileCoordinate-&gt;xTile = (position.xPosition / width);
     tileCoordinate-&gt;yTile = (position.yPosition / height);
  
     return tileCoordinate;
  }
  </code></pre>
  
  <p>and I wanted to call this in another source file or whatever, would I declare a pointer and above and return it? If so, When I call is from another class e.g.</p>
  
  <pre><code>CGPoint *currentTilePosition = tileForCoordinates(curPosition, 50, 50);
  </code></pre>
  
  <p>What happens to the pointer returned by malloc? Should it be freed or whats the story? :)</p>