All modules

Intermediate -- Module 04

Arrays & Pointers

Array-pointer decay, pointer arithmetic, multi-dimensional arrays, strings as char arrays, and dynamic memory with malloc/free -- with an eye on classic bugs (dangling pointers, off-by-one).

Video lesson

Downloadable notes

Plain-text lecture notes for Arrays & Pointers.

Download notes (.txt)

Practice problems

Reverse an array in place

Reverse an int array using two pointers moving toward each other, no extra array.

Warm-up

Roll your own strlen/strcpy

Implement my_strlen and my_strcpy using pointer arithmetic only, no indexing.

Core

Dynamic 2D matrix

Allocate a ragged 2D matrix with malloc, fill it, transpose it, then free every row and the row pointer array.

Stretch
Try these in the playground →

Module quiz

1. When an array name is used in most expressions, it decays to:

2. What does `*(arr + i)` mean for an int array `arr`?

3. Memory from malloc must eventually be released with:

4. A dangling pointer is one that: