A pointer is a variable that stores a memory location. It’s not magic, and it shouldn’t be confusing, as long as you keep the basic mantra in your head:
A pointer is a variable that stores a memory location.
A memory location stored in a pointer references another variable or a buffer (like an array). Therefore, the pointer must be initialized before it’s used:
A pointer must be initialized before it’s used.
When the pointer variable in C is prefixed by the
*(asterisk) operator, it references the contents of the variable at the memory location. This duality is weird, of course, but it’s highly useful.
- Declare a pointer variable by using the
- Use the
&operator to grab the address of any variable in C.
- Arrays are automatically referenced by their memory locations, so you can use an array name without the
&prefix to grab its address.
- “Address” and “memory location” are the same thing.