As I compile and run this code, I get storage=3 and safe=5
I understand how storage is 3, but I don't know why safe is 5, instead of 3.
What is being carried over?
object.put(object.get() + object.takeout());
Since object.get() returns storage, which is 1, and object.takeout() returns safe, which is 2, that code becomes the same as object.put(1 + 2); // So now storage = 3 .
Now, we get to object.insert(object.get() + object.takeout());.
Now object.get() returns storage, but storage is now 3 (because of the last line). object.takeout() is still 2 (since safe never got changed), so that call becomes object.insert(3 + 2); // So now safe = 5 .