Pointers and Memory Management

Lesson 12 of 20

Meet the & and * operators — store addresses, follow them, and let functions change your real variables in place.

The big picture

Memory has addresses

Pointers are how C talks about memory itself — an address is just a number that names a location.

A pointer is an address

A pointer is a variable whose value is the memory location of another variable.

& takes, * follows

&x produces the address of x; *p follows an address back to the value stored there.

Write through the arrow

*p = 42 changes the variable p aims at — the pointer itself just holds a location.

Why functions need them

C arguments are copies. Passing addresses is the only way a function can change your real variables.