title: Deleting an object after creating a pointer to it [Objective-C]
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9354215/does-lastobject-in-nsmutablearray-return-a-copy-of-the-object">Does lastObject in NSMutableArray return a copy of the object?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm following Stanford course on iOS development and I have a doubt.
  The thing is that I have an array (operandStack) with "operands" (NSNumbers) and I want a function that pops out the last element and then erase it from the array. This is what the tutorial sais (and it works):</p>
  
  <pre><code>- (double)popOperand
  {
      NSNumber *operand = [self.operandStack lastObject];
      if(operand) [self.operandStack removeLastObject];
      return [operand doubleValue];
  }
  </code></pre>
  
  <p>My question is: if with NSNumber *operand we're just "pointing" to the last object and in the next line we remove this last object, how is it possible that we then return it? I mean, if we remove the last object and operand is just pointing to that object, then operand should be pointing to nothing, so I can't understand how it's possible that we can return operand...
  I'd understand the code if operand was a copy of the last object of the array, but this is not the case...</p>
  
  <p>Sorry for my english :S I hope I made myself clear.</p>
  
  <p>Thanks,</p>
  
  <p>Carlos</p>