|
Re: C++ help: Understanding pointers?
My professor (from the dark ages) explained pointers like this. Think of memory as a bunch of numbered mailboxes. If you declare a simple variable that is like going to a mailbox (the address) and getting your letter (data). A pointer is going to a mailbox (address of the pointer) and getting a slip of paper that has another mailbox number (address of the data) on it. You then open the next mailbox and their is your letter (data). Make sense?
Pointers are not just an arbitrary concept put in languages to cause us headaches. They mirror capabilities in the hardware. Most computers have machine instructions that use "indirect addressing" or "indirected indexed addressing" modes. Pointers in C and C++ are indirect addressing in a high level language.
Anyways - add the concept that pointers increment by the size of the object they point to (so incrementing a pointer to an integer adds 4) and you are good to go.
__________________
Fast, cheap or working - pick any two!
Last edited by wireties : 22-03-2012 at 15:47.
|