Logo
Articles Compilers Libraries Books MiniBooklets Assembly C++ Rust Go Linux CPU Others Videos
Advertisement

Article by Ayman Alheraki on April 1 2026 02:22 PM

Pointers in Modern C++

Pointers in Modern C++

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.

Basic pointer declaration

Here:

  • &value means “the address of value”,

  • ptr stores that address,

  • *ptr means “the object pointed to by ptr”.

Address-of and indirection

Two operators are fundamental:

  • & gives the address of an object,

  • * dereferences a pointer to access the pointed-to object.

Changing an object through a pointer

Pointers can be reassigned

Unlike references, pointers can be changed to point somewhere else.

Pointers can be null

A pointer can intentionally point to nothing.

This is one of the major differences between pointers and references.

Pointers to dynamic objects

Pointers are often associated with dynamic allocation:

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.

Pointers are objects too

A pointer itself has storage, a type, and a value.

Here:

  • value is an int object,

  • ptr is an int* object,

  • the value stored in ptr is an address.

Advertisements

Responsive Counter
General Counter
1195539
Daily Counter
2590