My current stance on pointers

Pointers can seem quite complex, but they’re actually much easier to understand than at first glance. This is coming from someone that has spent several hours trying to understand how they work, and even gave up learning C++ a number of years ago because I couldn’t figure out how to use pointers and why they were useful.

After some studying, my understanding is that pointers literally just point to an address in memory. This is incredibly powerful because you can also perform pointer arithmetic to change between addresses in memory, and manipulating the values around. But, as the saying goes - with great power, comes great responsibility.

When I first started learning about pointers, I really struggled because I never understood that pointers and de-referencing are different things, but they use the same asterisk (*) operator. When you de-reference, you are asking for the value that the pointer is pointing to. The wording seems so complicated, but to better explain it – you’re asking for the value, not the address. When you use the ampersand (&) operator, you are instead getting the address-of.

For me, learning the difference between the three operators really helped understand the concept of pointers:
&x (address of),
int* p; (pointer), and
*p = 5; (de-reference)

Privacy & Terms