A pointer is a variable that stores the memory address of another variable.
&x → address of variable x
*ptr → value at the address stored in ptr
Pointers can be incremented or decremented.
A pointer that does not point to any valid memory.
Dynamic memory management
Efficient array handling
Used in data structures (linked lists, trees)
A reference is an alias (alternative name) for an existing variable.
| Pointer | Reference |
|---|---|
| Stores address | Alias of variable |
| Can be reassigned | Cannot be reassigned |
| Can be NULL | Cannot be NULL |
Uses * to access value | Accessed like normal variable |
Pointers store addresses
References are safer and easier to use
Pointers support dynamic memory
References are commonly used in functions
Pointers and references are powerful features in C++ that allow efficient memory access and manipulation.
Take quizzes related to this topic and see where you stand!
Start Quiz Now