In ScreenFact::getScreen() the int pointer that you pass to the new Test class points to an int that is local to that function i.e. when getScreen() returns, that int no longer exists and the pointer is no longer valid - it points to some random memory on the stack which is why you see it randomly changing.