Article by Ayman Alheraki on April 1 2026 02:22 PM
A pointer is an object that stores the address of another object or function. Unlike a reference, a pointer is itself a separate object with its own value.
x
int main() { int value{10}; int* ptr = &value;
std::cout << value << '\n'; std::cout << *ptr << '\n';}Here:
&value means “the address of value”,
ptr stores that address,
*ptr means “the object pointed to by ptr”.
Two operators are fundamental:
& gives the address of an object,
* dereferences a pointer to access the pointed-to object.
xxxxxxxxxxint value{7};int* ptr = &value;
int copy = *ptr;xxxxxxxxxx
int main() { int value{10}; int* ptr = &value;
*ptr = 99;
std::cout << value << '\n'; // prints 99}Unlike references, pointers can be changed to point somewhere else.
xxxxxxxxxx
int main() { int a{10}; int b{20};
int* ptr = &a; std::cout << *ptr << '\n'; // 10
ptr = &b; std::cout << *ptr << '\n'; // 20}A pointer can intentionally point to nothing.
xxxxxxxxxxint* ptr = nullptr;This is one of the major differences between pointers and references.
Pointers are often associated with dynamic allocation:
xxxxxxxxxxint* ptr = new int(42);delete ptr;This is valid C++, but Modern C++ strongly discourages using raw owning pointers as a beginner's default style. Later chapters will show why smart pointers are usually better.
A pointer itself has storage, a type, and a value.
xxxxxxxxxxint value{5};int* ptr = &value;Here:
value is an int object,
ptr is an int* object,
the value stored in ptr is an address.