Brainlag
  1. C
  2. Advanced
30/38 lessons

Undefined behaviour

45 min4 exercisesPremium

What undefined behaviour in C really means, the usual suspects, why broken code often looks fine, and how to watch it happen and defend against it.

The skill
Recognise the common kinds of undefined behaviour and write checks that stop them before they happen.
You make
A fixed vote counter, an addition that refuses to overflow and a number reader that rejects values too big for an int.

Premium lesson

£7.99 a month or £59 a year. Cancel any time.

Builds on 29 Function pointers. Free to try: C Foundations and the playground.

Step 1 of 8
exercise_1.c

You've reached the good stuff.

4 exercises in this lesson, checked as you type. Premium opens every lesson after Foundations, in all four courses.

C, 32-bit: int and pointers are 4 bytes