LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

What is a pointer and how do & and * work?

A pointer is a variable whose value is a memory address; &x produces the address of x, and *p follows a pointer to read or write what it points at.

Address-of and dereference

* &a yields a's address (16); store it in ap and *ap reads or writes a's value (5). *

int a = 5, b = 7, c;
// ap holds the ADDRESS of a
int *ap = &a;

Memory visualization:

Variable:  a    b    c    ap
Address:  16   20   24   28
Value:     5    7    ?   16  ← ap contains address of a
                         ↓
                    points to a

The operators:

  • &a → "address of a" → returns 16 (where a lives)
  • *ap → "value at address in ap" → returns 5 (contents of a)
// Changes a to 10 (through the pointer)
*ap = 10;
// Now ap points to b
ap = &b;
// Changes b to 20
*ap = 20;

Pointer to pointer:

// app points to ap, which points to an int
int **app = ≈
// Changes the int that ap points to
**app = 30;

Tip: Visualize with https://pythontutor.com/c.html - it shows pointers as arrows!

Go deeper:

From Quiz: REVE1 / C Programming | Updated: Jul 10, 2026