I know which pointer stores memory address. And a variable stores a value. But taking into account that I have a class class player {}
and I create a variable player p;
and a pointer instance player *np = null;
What's the difference between these 2 declarations. What happens in the system, what are the advantages of using one or the other.
Considering the same class used earlier, I could say that creating an object of type player
and also creating a pointer of the same type and storing the address of that object is the same as creating a new player()
? That is:
player x;
player *z = &x;
is equivalent to:
player *z = new player