I understand that pointers allow a better use of memory. This is the scenario I keep using to wrap my mind around the use of pointers:
If you (possibly) use 100 arrays in a program, but you know that you only need to use one at a time, why not just use a pointer? You can use the
new keyword to allocate new memory for one array and then use the
delete keyword to free the memory, before using the same pointer again for the second array!
^^^Please let me know if that is an incorrect example.
Here is what I don't understand. Consider the following example (taken from my textbook):
1 2 3 4 5 6 7 8
|
struct things
{
int good;
int bad;
}
things grubnose = {3, 453};
things *pt = &grubnose;
|
How does this save memory?! You're already assigning static memory to structure when you create it, right? So even if you create a pointer to this structure, that static memory can not be saved, so what is the point in doing something like this???
Also, as a bonus question, when we talk about better using memory, what does that entail exactly?? Going back to the 100 array example near the top, would those 100 arrays be loaded into RAM when you first start the program? Or is "memory" referring to the overall size of the program?
Thanks for taking your time to read this!!! :)