All paths

Pointers and memory in C

What is really in 2 KB of RAM, and the idea that makes C what it is: addresses, pointers, arrays and strings by hand, structs, the stack, function pointers. Ends with a serial command line built from all of it.

Arduino Uno R3Free8 lessons5 h4 chapters2,796 XPCoding · Intermediate+150 XP

0 of 8 done

What you will build

4 projects, built step by step

8 lessons in 4 chapters, about 5 hours on a simulated Arduino Uno R3. Free, in your browser, every step checked by the simulator.

Chapter 1 project

Pointers

A variable that holds an address: declaring one, reading and writing through it with *, swap done right, NULL and the check before you follow it, and a button that fires at whatever the pointer aims at.

Open it in the simulator
Chapter 2 project

Strings by hand

A C string is chars and a zero byte: length, upper case and reverse written with pointers, a buffer overflow you can watch trample its neighbor, the bounded copy that stops it, and a compare that lights a lamp.

Open it in the simulator
Chapter 3 project

Stack and static

Where things live in 2 KB: globals low, the stack high and growing down with every call, a local that forgets against a static that remembers, and a buffer that eats the free RAM.

Open it in the simulator
Chapter 4 project

Project: a command parser

Everything in one program: a bounded line buffer, a tokenizer that splits in place into argv, a number parser, lamps found by name through a table, and a table of commands with function pointers. Add your own command, then make it yours.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Where things live

Addresses in the Uno's 2 KB, then pointers that hold them.

  1. Open236 XP

    Addresses

    Every variable lives at a numbered byte: where globals sit in the Uno's 2 KB, neighbors in an array, the bytes of a number stored little end first, and the map from 0x100 to 0x8FF.

    0 of 6 steps

  2. ProjectLocked472 XP

    Pointers

    A variable that holds an address: declaring one, reading and writing through it with *, swap done right, NULL and the check before you follow it, and a button that fires at whatever the pointer aims at.

    0 of 6 steps

4 questions, graded as you go.
Chapter 2

Arrays and text

Arrays as pointers, then strings walked by hand.

  1. Locked236 XP

    Arrays are pointers

    An array's name turns into the address of its first element: pointer arithmetic that counts in elements, a[i] as *(a + i), walking an array with a pointer, the sizeof trap in a function, and a lamp chaser that is a moving pointer.

    0 of 6 steps

  2. ProjectLocked472 XP

    Strings by hand

    A C string is chars and a zero byte: length, upper case and reverse written with pointers, a buffer overflow you can watch trample its neighbor, the bounded copy that stops it, and a compare that lights a lamp.

    0 of 6 steps

5 questions, graded as you go.
Chapter 3

Structs and the stack

Structs and the arrow, then where locals and statics live.

  1. Locked236 XP

    Structs and pointers

    A fleet of ships in an array of structs: sizeof with no padding on the AVR, the arrow operator, a copy against a pointer, a search that returns NULL, a button that flies, and a fourth ship.

    0 of 6 steps

  2. ProjectLocked410 XP

    Stack and static

    Where things live in 2 KB: globals low, the stack high and growing down with every call, a local that forgets against a static that remembers, and a buffer that eats the free RAM.

    0 of 5 steps

4 questions, graded as you go.
Chapter 4

Code as data

Function pointers, then a command parser built from everything.

  1. Locked236 XP

    Function pointers

    A pointer to code: one call that runs add or multiply, a sort that takes its order as a function, a callback for each element, and a table of lamp modes, with a police mode you add yourself.

    0 of 6 steps

  2. ProjectLocked498 XP

    Project: a command parser

    Everything in one program: a bounded line buffer, a tokenizer that splits in place into argv, a number parser, lamps found by name through a table, and a table of commands with function pointers. Add your own command, then make it yours.

    0 of 7 steps

4 questions, graded as you go.
Syllabus

Every lesson in the course

All 8 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Where things live

  1. AddressesEvery variable lives at a numbered byte: where globals sit in the Uno's 2 KB, neighbors in an array, the bytes of a number stored little end first, and the map from 0x100 to 0x8FF.
  2. PointersA variable that holds an address: declaring one, reading and writing through it with *, swap done right, NULL and the check before you follow it, and a button that fires at whatever the pointer aims at.
Chapter 2

Arrays and text

  1. Arrays are pointersAn array's name turns into the address of its first element: pointer arithmetic that counts in elements, a[i] as *(a + i), walking an array with a pointer, the sizeof trap in a function, and a lamp chaser that is a moving pointer.
  2. Strings by handA C string is chars and a zero byte: length, upper case and reverse written with pointers, a buffer overflow you can watch trample its neighbor, the bounded copy that stops it, and a compare that lights a lamp.
Chapter 3

Structs and the stack

  1. Structs and pointersA fleet of ships in an array of structs: sizeof with no padding on the AVR, the arrow operator, a copy against a pointer, a search that returns NULL, a button that flies, and a fourth ship.
  2. Stack and staticWhere things live in 2 KB: globals low, the stack high and growing down with every call, a local that forgets against a static that remembers, and a buffer that eats the free RAM.
Chapter 4

Code as data

  1. Function pointersA pointer to code: one call that runs add or multiply, a sort that takes its order as a function, a callback for each element, and a table of lamp modes, with a police mode you add yourself.
  2. Project: a command parserEverything in one program: a bounded line buffer, a tokenizer that splits in place into argv, a number parser, lamps found by name through a table, and a table of commands with function pointers. Add your own command, then make it yours.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Pointers and memory in C

Is Pointers and memory in C free?

Yes. All 8 lessons of Pointers and memory in C are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Arduino Uno R3?

No. Every lesson runs on a simulated Arduino Uno R3 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Pointers and memory in C take?

About 5 hours: 8 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Pointers, Strings by hand, Stack and static and Project: a command parser.

Where do I start?

With "Addresses", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.