Everything in a program lives at a specific numeric address in memory.
- Address-of Operator (
&): Gets the memory location of a variable. - Pointer (
*): A variable that stores a memory address. - Dereference Operator (
*): Goes to the address stored in a pointer and gets the value.
int x = 42;
int* ptr = &x; // ptr holds the address of x (e.g., 0x7ffd...)
// Accessing
std::cout << ptr; // Prints the address (0x7ffd...)
std::cout << *ptr; // Prints the value (42)Pointer Arithmetic
Allows you to use a 1D array to represent higher dimensional (2D, 3D, etc.) data. 3D example: