What exactly is a Pointer?
A Pointer is simply a variable that stores the memory address of another variable.
Regular Variable
Stores the actual data (e.g. 10, 'A').
Pointer Variable
Stores a memory address (e.g. 0x104A).
Declaring Pointers & The '&' Operator
To work with pointers, you place an asterisk (*) between the data type and the name, and use the & operator to get an address.
🔍 The Address-of Operator (&)
& is a unary operator that returns the memory address of its operand. Hover over the highlighted code on the left!
int * can only point to an int. A char * can only point to a char.
The Dereference (*) Operator
Once a pointer has an address, we can use the asterisk (*) to access or modify the actual value stored at that address.
🔍 Inspect Dereferencing
⭐ The Two Faces of the Asterisk
int *p;"I am creating a pointer variable."
*p = 10;"Go to the address inside p and change the data."
The "Manager's Pointer" in Action
The game is on the line. The pitch coordinate (Address 0x7FFE) is fixed on the grass. You are the Manager! Use your Pointer to substitute a new player into the Right Winger zone.
int *RW_Position = &rw_jersey;
This pointer directs us to the Fixed Coordinates on the pitch:
Salah
Value of rw_jersey: 11
*RW_Position), the manager can remotely target that exact spot and replace the Player inside it (Data) with a new one!
Null Pointers & Seg-Faults
What happens if you create a pointer but don't give it an address?
⚠️ The Garbage Address Trap
In C, uninitialized pointers point to random garbage addresses. Modifying those addresses might overwrite critical system memory, causing an instant crash (Seg-Fault).
NULL (a macro for memory address 0) if you don't have a valid address yet.