C Playground
A starter program to experiment with. Edit it here, press Copy, paste it into a file called main.c, and compile and run it with cc -std=c17 -Wall -Wextra main.c -o main && ./main. Lesson 2 shows how to install a compiler.
Output
Backpack 1 x 39.90 = 39.90 Notebook 4 x 3.50 = 14.00 Pen 10 x 1.20 = 12.00 Total: 65.90
Ideas to try
- Apply a 10% discount when the total is over 50 (lesson 16).
- Read the items from a CSV file instead of hard-coding them (lesson 47).
- Let the user add items from the keyboard, growing the basket with
realloc(lessons 15 and 37). - Store prices as whole cents to avoid rounding errors (lesson 9).
- Compile with
-fsanitize=address,undefinedand try introducing an off-by-one bug in the loop (lesson 38).
Compiling without installing anything
Online compilers such as Compiler Explorer (godbolt.org) can compile and run C in your browser — useful for quick experiments. Choose a recent GCC or Clang and add -std=c17 -Wall -Wextra to the compiler options.