The Dereference Operator
You'll learn how to use the dereference operator (*) to access and modify the actual value stored at the address a pointer holds.
What Does Dereferencing Mean?
A pointer variable stores a memory address—not the value itself. When you want to work with the actual data at that address, you need to dereference the pointer using the * operator. Think of it like this: if a pointer is a street address written on paper, dereferencing is actually going to that house and opening the door to see what's inside.
Using the Dereference Operator
Place * in front of a pointer variable to access or change the value at its address:
int num = 42;
int* ptr = # // ptr holds the address of num
int value = *ptr; // Dereference: read the value at ptr's address
// value is now 42
*ptr = 100; // Dereference: write a new value to that address
// num is now 100
When you write *ptr, you're saying "give me the thing that ptr points to." You can read from it or assign to it, just like a normal variable.
Key Distinction
ptr(without*) → the memory address itself*ptr(with*) → the value stored at that address
The Analogy
If & (address-of operator) says "where does this live?" then * (dereference) says "what's actually there?"
Key Takeaway: The dereference operator * lets you access or modify the value stored at a pointer's address, turning the pointer back into usable data.