QUICK START:HTMLCSSJavaScriptTypeScriptPythonSQLReactNext.jsNode.jsDSASystem DesignDevOpsCybersecurityAI / ML
Advanced 18 min readModule: Module 3: Pointers, References & Pointer Arithmetic

Memory Addresses, Pointers & References

Master direct memory addressing (&), pointer dereferencing (*), null pointers (nullptr), and references.

What You Will Learn in This Lesson

  • How pointers store memory addresses of variables
  • Dereferencing pointers to mutate underlying memory (*ptr = val)
  • References (const Type&) for zero-copy function parameter passing

Introduction & Core Concept

A pointer is a variable that stores the memory address of another variable. References provide safe aliases to existing variables without nullability risks.
WHY DOES THIS MATTER IN THE REAL WORLD?

Passing 1MB objects by value makes an expensive copy. Passing by const reference (const BigObject&) takes 0 copies (8 bytes pointer).

Pointer & Reference Manipulation

cpp
cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
void increment(int& ref) { ref += 1; }
int main() {
int value = 10;
int* ptr = &value;
*ptr = 20; // Mutate via pointer
increment(value); // Mutate via reference
std::cout << "Final Value: " << value << " at address: " << ptr << std::endl;
return 0;
}

Line-by-Line Technical Breakdown

1Always use nullptr instead of NULL or 0 for uninitialized pointers.

Try It Yourself (Interactive Editor)

Modify the code in real-time and click Run to test live browser output and console logs.

Intelligent Code Runner & Live Sandbox[CPP]
CPP SOURCE EDITOR
Interactive Live Code

Industry Best Practices & Professional Standards

  • Pass large structs and vectors by const reference (const std::vector<int>&).

Lesson Summary & Core Takeaways

  • Pointers and references give direct control over computer memory.