Skip to content
Guest
Learn C · Course Syllabus Show lessons
Memory & Data · 10 min read · Intermediate

Pointers & Memory Addresses

Demystify pointers using the address-of operator (&) and dereference operator (*) to mutate data in place.

What you'll learn

  • Explain what a pointer stores (a memory address)
  • Take an address with & and read or write through a pointer with *
  • Write a swap(int *a, int *b) function that mutates caller variables

A pointer is a variable whose value is the memory address of another variable. Mastering two operators unlocks pointers completely:

  • &x (address-of): produces the memory address of x.
  • *p (dereference): reads or writes the value stored at address p.

Fill-in-the-Blank Exercise

Swap Two Integers via Pointers

Dereference pointers a and b to swap the caller's values in place.

void swap(int *a, int *b) {
  int tmp = a;
  *a = *b;
  *b = tmp;
}
// Call site:
swap(x, &y);

Interactive Code Lab

Cpointers.c
Expected OutputClick “Run Live” to compile with GCC 13 (C11)
After swap: x=25, y=10

Check Your Understanding

Score: 0 / 1

1. If int x = 42; and int *p = &x;, what does *p evaluate to?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind