C++ Dereference Operator
π C++ Dereference Operator (*)
In C++, the dereference operator (*) is used to access or modify the value stored at the memory address held by a pointer.
πΉ 1. What Does Dereferencing Mean?
-
A pointer stores an address
-
Dereferencing means getting the value at that address
πΉ 2. Basic Dereference Example
πΉ 3. Dereference to Modify Value
β‘ Value changed using dereference.
πΉ 4. Dereference in Functions
πΉ 5. Dereference with Arrays
πΉ 6. Dereference a Pointer to Pointer
πΉ 7. Dereference vs Declaration (* Meaning)
π Same symbol, different meanings based on context.
πΉ 8. Dereference with const
Pointer to Constant
Constant Pointer
β Common Mistakes
β Dereferencing Uninitialized Pointer
β Correct
β Dereferencing Null Pointer
π Dereference vs Address-of
| Operator | Meaning |
|---|---|
&x |
Address of x |
*p |
Value at address p |
π Summary
-
Dereference operator
*accesses value at address -
Used with pointers and pointer-to-pointer
-
Can read or modify data
-
Must never dereference NULL or uninitialized pointers
