Interactive Computer Science Tutoring

Learn programming concepts interactively

AHA Schools Logo

Pointers in C - The Postal Service Analogy

Master C's most powerful feature: direct memory address manipulation

What Are Pointers? The Postal Service Analogy 📮

Think of pointers like a mail delivery system. Instead of carrying packages directly, mail carriers use addresses to find and deliver to the right houses.

House (Variable): int age = 25
Address: &age (like "123 Main Street")
Mail Carrier (Pointer): int *ptr = &age

Just like a mail carrier can visit the address to deliver or pick up mail, a pointer can dereference (*ptr) to access or modify the value stored at that memory address!

Memory City Map 🏙️3 variables • 0 pointers
Click on memory locations to select them, see how pointers connect variables
age
0x1000
Type:int
Value:25
salary
0x1004
Type:float
Value:50000
grade
0x1008
Type:char
Value:'A'
Hire a Mail Carrier (Create Pointer)
Create a pointer that can deliver to a specific variable
Mail Delivery (Dereference Pointer)
Use a pointer to access or modify the value at its target address
Quick Pointer Examples
Interactive Learning
Pointer Mastery Guide

📬 Postal Service Analogy:

  • Variable = House: Has an address and stores a value
  • Pointer = Mail Carrier: Knows the address and can deliver/pick up
  • &variable = Address: Getting the house address
  • *pointer = Delivery: Going to the address and accessing the contents

🎯 Pointer Operations:

  • Declaration: int *ptr (creates a mail carrier for int addresses)
  • Assignment: ptr = &variable (give the mail carrier an address)
  • Dereferencing: *ptr (mail carrier goes to address and gets/sets value)
  • Address arithmetic: ptr++ (move to the next house)

⚠️ Common Pitfalls:

  • Uninitialized pointers: Mail carrier without an address = dangerous!
  • NULL pointer dereferencing: Trying to deliver to address "nowhere"
  • Wild pointers: Mail carrier with wrong/old address
  • Memory leaks: Forgetting to return dynamically allocated "houses"
C Pointers Code
Interactive C code with memory visualization
History0/5
Pointer operations and memory access

No operations yet

Start by adding or modifying elements