Let’s Review Pointers

Pointers cause a lot of heartburn among students.  Hopefully this post will address some or all of the things you may be struggling with in the world of pointers.

For pointers to make sense, particularly the parts of them that are important for this class, you need to remember a few fundamental pieces of information:

  • Each location where data can be stored has an address.
    • Analogy: Every post office box in Hughes Trigg has an individual address.  If each didn’t, then the workers wouldn’t know what mail goes in which box.
    • Note that even pointers have addresses.  So, if I have
      int* x;
      

      x is a pointer to an integer, so it can store an address.  It is also a variable, so it has an address where it is stored.

  • If I have an address, I can get to what is stored at that address by using the dereference (*) operator.
    • Analogy continued: If I use an address of a particular PO Box to go retrieve the mail inside of said box, the act of retrieving the mail (or putting another piece of mail in the box) would be dereferencing.
    • Notice that in the beginning of that sentence, I didn’t say “if I have a pointer variable”.  If I have any expression that resolves to an address, I can go to that address by using the dereference operator.
  • If I have a variable and I need to get the address of that variable, I can use the address-of (&) operator.

With that said, below are links to previous posts on my website, some Vimeo screencasts that I’ve made, and other resources that should help with developing a deeper understanding of pointers.

Speak Your Mind

*

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.