C practice
Practice C programming online: 10 exercises, graded problems and a playground
C is where printf, pointers and manual memory live, and the exercises here meet them one at a time. Your source is compiled by clang, running inside your browser via Emscripten, so warnings and errors are the compiler's real ones. Programs read from scanf and fgets using the input box, and the output panel shows exactly what your program printed — including the newline you forgot.
- checked exercises
- 10
- graded problems
- 0
- lessons
- 8
- cheat sheet
- 1
C practice exercises
How the path works →In order, each one introducing a single new idea. Press Run to check your answer; hints open one at a time.
- Hello, Out Loudprintf() puts text on the screen
- Name TagA variable is declared with a type, and holds one value under a name
- Party PlannerC does arithmetic with + - * / and %, and / between two ints throws away the remainder
- Umbrella or Notif/else chooses between two different blocks of code
- Countdowna for loop repeats a block a fixed number of times
- The Clapping GameAn if inside a for loop is decided again on every pass
- The Scoreboarda number between % and the conversion letter gives printf a fixed field width
- Packing ListAn array holds several values of one type in order, indexed from zero with []
- Rainfall WeekA variable declared before a loop carries its value from one pass to the next
- The Cafe TicketAssembling a complete program from parts you already know
C lessons behind the practice
All lessons →- Your First C ProgramWhat every C program must contain - the main function, printf and its format specifiers, escape sequences, and what a compiler actually does to your source file before anything runs.
- Variables and Types in CWhy every C variable must be given a type up front - int, double and char, what sizeof really measures, the integer division trap, and how overflow behaves differently for signed and unsigned values.
- Control Flow in C: if, switch and LoopsHow C chooses between paths and repeats work - if and else if, why any nonzero value counts as true, switch and deliberate fall-through, while, do-while and for, and steering a loop with break and continue.
- C Functions: Prototypes, Arguments and Return ValuesHow to define and call a function in C, why the compiler needs a prototype before the call, what pass by value really means for your variables, and how return values, void and recursion fit together.
- Arrays and Strings in CHow a C array stores a fixed run of same-typed values, why a string is just a char array with a zero byte on the end, how strlen and the string.h functions use that terminator, and why writing past the end of a buffer is so dangerous.
- Pointers in CWhat a pointer actually holds, how & and * work together, why pointer arithmetic counts elements rather than bytes, how passing a pointer lets a function change its caller's variable, and how to write a working swap.
- Dynamic Memory in C: malloc and freeHow to ask for memory while a program is running, why every malloc must be checked against NULL and matched by exactly one free, and what leaks, dangling pointers and double frees actually are.
- Structs and typedef in CHow to group related values into one type with struct, reach members with the dot and arrow operators, shorten the name with typedef, and build and search an array of structs.
C cheat sheet
Everyday syntax on one page, for when you remember the idea but not the spelling.
Coding interview questions
Original questions with full model answers, for when the practice is going somewhere specific.
Questions people ask
- Which C standard and compiler are used?
- clang, built into the browser through Emscripten, compiling as C with the defaults a modern clang uses. If you want a specific standard flag, the C guide covers compiling locally with gcc or clang.
- Can I use scanf and read input?
- Yes. Whatever you type into the input box is the program's standard input, so scanf, getchar and fgets all work the way they do at a terminal.
- Will undefined behaviour crash the page?
- No. Your program runs in a sandboxed WebAssembly instance; an out-of-bounds write or a bad pointer can crash that instance, which is reported as a runtime error, but it cannot affect the page or your computer.
- What comes next after these exercises?
- Once the 10 exercises are done: 8 in-depth lessons, a cheat sheet for the syntax and the C++ path, which is the natural next language from here.
Practise another language
The same kind of practice hub exists for Python, JavaScript, TypeScript, Java, C++, C#, Go, PHP, Ruby, SQL, R and Bash & the Shell.