Skip to content

Array management by pointer

So pay attention: a new pointer's declaration (new(pEmpTemp);) automatically causes the declaration of a new variable of type it points too.

But you have not this variable's name (the label), just the pointer to it; in this way you decide to manage it only with pointers.

Surely you can declare a Temployee variable with a label, and then create a pointer to it.
But our goal is to give you a clear vision of logical separation that these two approaches entail.

On opposite side, how to delete a pointer from the array?
By-value: we have a value and simply we operate to delete it. The operation is safe in itself; you have not to expect random behaviors.
By-pointer: situation is different. If we delete the item pointer from array, we just put a bomb into our software.

Reason is that we only eliminate its membership to array, but pointer still lives, so - horrible - still points to another memory location.
What's the problem? you just said that by deleting a variable, we delete it completely!

Well... here the trap!

First of all, to be very rude, by deleting a variable you don't delete the corresponding hard disk sectors.

Second: deletion has a logical meaning, so that a deleted variable is a location memory become free, where free means free to be used again (by your software, with a different name; or by operating system, for its jobs).

A variable deletion is not dangerous, because it's not bound to anything else, differently from pointers.