100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C++

Pointers in C++

Learn what a pointer is, how to declare one, and how the `&` and `*` operators let you access and manipulate memory addresses directly.

PointersIntermediate7 min readJul 7, 2026
Analogies

1. Intro

A pointer is a variable that stores the memory address of another variable, instead of storing a data value directly. Every variable in a running program lives at some address in memory, and a pointer lets you capture that address and work with it. Pointers are central to C++ because they enable dynamic memory management, efficient array/function handling, and low-level control that is not possible with plain variables alone.

🏏

Cricket analogy: A pointer is like a locker number written on a card rather than the bat itself — the card doesn't hold the bat, it tells you exactly which locker in the pavilion, like Room 12, currently holds Virat Kohli's bat.

2. Syntax

cpp
dataType* pointerName;      // declaration
pointerName = &variable;    // assignment (address-of)
*pointerName;                // dereference (access the value)

3. Explanation

A pointer declaration such as int* p; creates a variable p that is meant to hold the address of an int. The & operator, called the address-of operator, returns the memory address of a variable — &x gives the address where x is stored. The * operator, called the dereference operator, is used in two different contexts: in a declaration (int* p) it marks p as a pointer type, while in an expression (*p) it means "go to the address stored in p and get the value there". Every pointer also has a type (int*, double*, char*, ...) which tells the compiler how to interpret the bytes at that address and how far to move for pointer arithmetic.

🏏

Cricket analogy: Declaring int* p is preparing an empty locker tag meant for a batting-average box; &average gives you the actual locker number where Kohli's average lives, and *p means "open that locker and read the number inside" — the tag's type tells you it's sized for an average, not a full scorecard.

4. Example

cpp
#include <iostream>
using namespace std;

int main() {
    int x = 42;
    int* p = &x;       // p stores the address of x

    cout << "Value of x: " << x << endl;
    cout << "Address of x: " << &x << endl;
    cout << "Value stored in p: " << p << endl;
    cout << "Value pointed to by p: " << *p << endl;

    *p = 100;           // modify x through the pointer
    cout << "New value of x: " << x << endl;

    return 0;
}

5. Output

text
Value of x: 42
Address of x: 0x7ffee4c5a9ac
Value stored in p: 0x7ffee4c5a9ac
Value pointed to by p: 42
New value of x: 100

6. Key Takeaways

  • A pointer is a variable that stores a memory address, declared as dataType* name;.
  • &variable yields the address of that variable (address-of operator).
  • *pointer dereferences the pointer, giving access to the value at that address.
  • Modifying *p changes the original variable, since p points directly to its memory location.

Practice what you learned

Was this page helpful?

Topics covered

#CStudyNotes#Programming#PointersInC#Pointers#Syntax#Explanation#Example#StudyNotes#SkillVeris#ExamPrep