Skip to main content
Engineering LibreTexts

8.4: Pointer Math

  • Page ID
  • One of the really neat things about pointers is pointer math. Returning to our example of pc at address 3000, if you increment pc, as in pc++; you’ll get 3001. No surprise, right? If, on the other hand, you had a pointer to a double, pd, at address 3000 and you incremented it, you wouldn’t wind up with 3001. In fact, you’d wind up with 3008. Why? This comes down to how large the thing is that we’re pointing at. doubles are 8 bytes each. If you had a bunch of them, as in an array, incrementing the pointer would get you the next item in the array. This is extremely useful. Note that adding and subtracting to/from pointers makes perfect sense, but multiplying, dividing, and higher manipulations generally make no sense and are to be avoided.

    • Was this article helpful?