Zum Inhalt springen

C-Tutorial

Learn C from your first printf to pointers, memory management, structs, files, data structures and threads. Real C compiled in your browser, quizzes and projects.

Getting Started

  1. 1 Erste Schritte mit C Learn what the C programming language is, where it runs and why it still matters. Write, compile and run your first C program with printf in your browser.
  2. 2 Wie C funktioniert: Kompilieren und Linken See how C source code becomes a program. Learn the preprocessor, compiler, assembler and linker, object files, C standards from C89 to C23, and warning flags.
  3. 3 C-Syntax Learn the basic syntax rules of C - main, statements and semicolons, blocks, headers, whitespace and case sensitivity - and how to read compiler errors.
  4. 4 Kommentare Learn C comments - block comments with /* */, line comments with //, why block comments do not nest, documenting functions, and useful habits.
  5. 5 Ausgabe mit printf Master printf in C - common format specifiers (%d, %zu, %f, %s, %p, %x), width, precision and flags, puts and putchar, escapes and format warnings.
  6. 6 Eingaben lesen mit scanf und fgets Read user input in C safely - scanf and its return value, the leftover newline trap, fgets with sscanf or strtol, getchar, and reading until EOF.
  7. 7 Schlüsselwörter und Bezeichner Learn every C keyword up to C23, grouped by purpose, plus the rules for valid identifiers, names reserved for the compiler and library, and naming conventions.

Variables and Types

  1. 8 Variablen Learn how C variables work - declaring and initializing them, assigning new values, why uninitialized variables are dangerous, and a first look at scope.
  2. 9 Datentypen Learn C's basic data types - char, int, long, float, double and bool - how sizeof works, why sizes vary by platform, signed vs unsigned, and how to pick a type.
  3. 10 Ganzzahltypen Master C integers - ranges of short, int, long and long long, exact-width types from stdint.h, printing them with inttypes.h, overflow rules and C23 literals.
  4. 11 Gleitkommazahlen Learn how float, double and long double store numbers in C, why 0.1 + 0.2 isn't 0.3, how to compare floats safely, and how infinity, NaN and float.h work.
  5. 12 Zeichen und ASCII Learn how C stores characters as small integers, read the ASCII table, use escape sequences and ctype.h functions safely, and handle the signedness of char.
  6. 13 Boolesche Werte Learn how C represents true and false - zero and non-zero, _Bool and stdbool.h, the C23 bool keywords, why comparisons return int, and common boolean bugs.
  7. 14 Konstanten: const, #define, enum und constexpr Learn every way to name a fixed value in C - literals, const variables, #define macros, enum constants and C23 constexpr - how they differ, and when to use each.
  8. 15 Typumwandlungen und Casts Understand C type conversions - integer promotion, the usual arithmetic conversions, signed/unsigned comparison traps, narrowing, float-to-int truncation and explicit casts.
  9. 16 Typgrenzen: limits.h und float.h Find the exact range of every C type with limits.h, stdint.h and float.h - INT_MAX, CHAR_BIT, SIZE_MAX, DBL_EPSILON - and detect integer overflow safely, including C23 ckd_add.
  10. 17 typedef Learn C typedef: create type aliases, simplify struct and function pointer declarations, see how size_t and uint32_t work, and know when typedef hides too much.

Operators

  1. 18 Arithmetische Operatoren Learn C's arithmetic operators + - * / %: integer division and truncation, remainders of negative numbers, division by zero, integer promotion and mixed types.
  2. 19 Zuweisungs- und Inkrementoperatoren Learn C's assignment operators: = as an expression, compound assignment like += and <<=, prefix vs postfix ++ and --, and why i = i++ is undefined behavior.
  3. 20 Vergleichs- und logische Operatoren Learn C's relational and logical operators: 0 and 1 results, short-circuit && and ||, signed vs unsigned traps, comparing floats safely, and comparing pointers.
  4. 21 Bitweise Operatoren Learn C's bitwise operators & | ^ ~ << >>: print binary, build masks, set, clear and toggle bits, pack flags, avoid undefined shifts, and use C23 stdbit.h.
  5. 22 Operatorrangfolge, ternärer Operator und Komma-Operator The full C operator precedence and associativity table, grouping vs evaluation order, the ternary ?: and comma operators, sizeof, and common precedence bugs.

Control Flow

  1. 23 if, else if und else Learn C's if, else if and else: how conditions are tested, ordering else-if chains, nesting, the dangling else, = vs == bugs, empty bodies and guard clauses.
  2. 24 switch-Anweisungen Learn C's switch statement: case labels, break and fall-through, C23 [[fallthrough]], default, switching on enums with -Wswitch, and when if-else is better.
  3. 25 while- und do-while-Schleifen Learn how while and do-while loops work in C, how to read input until EOF or a sentinel value, validate input with retries, and avoid infinite loops.
  4. 26 for-Schleifen Master the C for loop - how its three parts run, declaring the loop variable in the header (C99), counting up and down, nested loops and off-by-one bugs.
  5. 27 break, continue und goto Learn how break and continue control C loops, how to leave nested loops, and why goto for error cleanup is the one use of goto that C programmers accept.

Functions

  1. 28 Funktionen Learn how to define and call functions in C, choose return types, write void functions, and split a program into small named pieces that are easy to test.
  2. 29 Parameter und Rückgabewerte How C passes arguments by value, how return values work, how to return several results with out-parameters or structs, and how arrays behave as parameters.
  3. 30 Parameterübergabe: Call by Value und per Zeiger See exactly what C copies when you call a function, how pointers simulate call by reference, and how arrays, structs and pointer parameters behave in practice.
  4. 31 Deklarationen, Prototypen und Header Learn how declaring and defining a C function differ, why prototypes matter, what (void) versus () means before and after C23, and how header files work.
  5. 32 Die Funktion main im Detail Learn every valid form of main in C, what its return value means, how falling off the end works, and the real difference between return, exit and atexit.
  6. 33 Rekursion Learn recursion in C - base cases, the call stack, factorial, Fibonacci, fast power and Tower of Hanoi, stack overflow, and when a loop is the better choice.
  7. 34 Gültigkeitsbereich und Speicherklassen Learn C scope, lifetime and linkage - block and file scope, shadowing, static local and global variables, extern, register, auto and thread_local explained.
  8. 35 Variadische Funktionen Write C functions that take any number of arguments with stdarg.h. Learn va_list, va_start, va_arg, va_copy and va_end, build a mini printf, and avoid the traps.
  9. 36 inline-Funktionen Learn what inline really means in C, why a plain inline function can fail to link, how static inline works in headers, and how C's rules differ from C++.
  10. 37 Funktionszeiger Master C function pointers - declaring and calling them, typedefs that make them readable, callbacks with context, dispatch tables, and qsort comparators.
  11. 38 Verschachtelte Funktionen (GNU-Erweiterung) und Alternativen Standard C has no nested functions. See how the GCC extension works, why it is risky, and the portable alternatives, from static helpers to callbacks with a context.

Arrays and Strings

  1. 39 Arrays Learn C arrays from scratch - declaring, initializing and designated initializers, indexing and loops, sizeof tricks, passing arrays to functions, and bounds errors.
  2. 40 Mehrdimensionale Arrays Work with 2D and 3D arrays in C - nested initializers, row-major memory layout, passing matrices to functions, variable-length arrays, and allocating 2D arrays.
  3. 41 Zeichenketten Learn how C stores text - char arrays and the null terminator, string literals and why they are read-only, sizeof vs strlen, and printing and reading strings safely.
  4. 42 Zeichenkettenfunktionen A practical tour of string.h - strlen, strcpy and strcat, strcmp, strchr and strstr, strspn, memcpy, memmove and memset, and splitting text with strtok.
  5. 43 Sichere Zeichenkettenbehandlung Prevent buffer overflows in C - why gets was removed, bounded input with fgets, snprintf with truncation checks, strncpy pitfalls, memccpy and strdup, and lines of any length.
  6. 44 Zeichenketten und Zahlen umwandeln Convert strings to numbers in C the safe way with strtol and strtod, detect bad input and overflow, and turn numbers into text with snprintf and sscanf.

Pointers

  1. 45 Zeiger Learn C pointers from scratch - memory addresses, the & and * operators, printing with %p, dereferencing, NULL and C23 nullptr, and the bad pointers to avoid.
  2. 46 Zeigerarithmetik Learn C pointer arithmetic - how p + 1 moves by whole elements, subtracting pointers with ptrdiff_t, the one-past-the-end rule, comparisons and what is undefined.
  3. 47 Zeiger und Arrays Understand how C arrays turn into pointers, why a[i] means *(a + i), how to pass arrays to functions safely, and why sizeof gives different answers.
  4. 48 Zeiger auf Zeiger Learn C double pointers - what int ** means, how a function changes the caller's pointer, arrays of strings, argv, and row-by-row 2D arrays with malloc.
  5. 49 const und Zeiger Learn the difference between a pointer to const and a const pointer in C, how to read the declarations, and how const-correct function parameters prevent bugs.
  6. 50 void-Zeiger und generischer Code Learn how C's void * holds any object address, how memcpy and qsort use it to work on any type, how to write generic functions safely, and what C23 typeof adds.
  7. 51 Zeiger und Funktionen Use pointers with C functions - swap values, return several results through out-parameters, return pointers safely, avoid dangling pointers and understand restrict.
  8. 52 Der restrict-Qualifizierer Learn what pointer aliasing is, how the C99 restrict qualifier lets compilers optimize, the exact promise you make, and how memcpy, memmove and your own functions use it.

Memory Management

  1. 53 Dynamischer Speicher: malloc, calloc, realloc und free Learn dynamic memory in C - allocate on the heap with malloc and calloc, grow blocks safely with realloc, check for NULL, use the sizeof *p idiom and free memory.
  2. 54 Speicherfehler Learn the classic C memory bugs - leaks, double free, use-after-free, buffer overruns and uninitialized reads - how Valgrind and AddressSanitizer find them, and safe habits.
  3. 55 Speicherlayout eines C-Programms See how a running C program is laid out in memory - the text, data and bss segments, the heap and the stack - print real addresses, and learn why the stack has limits.
  4. 56 Ein dynamisches Array bauen Build a growable array in C - a vector of ints with capacity doubling, push, insert and remove, then a generic version with void pointers and an element size.

Structures and Unions

  1. 57 Strukturen Learn C structures - define a struct, initialize it with designated initializers, access members, copy and compare structs, return them from functions and use compound literals.
  2. 58 Strukturen und Zeiger Learn how C structures and pointers work together - the -> operator, passing structs by pointer, const struct parameters, heap-allocated structs and self-referential structs.
  3. 59 Arrays von Strukturen und verschachtelte Strukturen Learn to build tables of records in C with arrays of structures, search and total them, sort them with qsort by one or more keys, and nest structs inside structs.
  4. 60 Unions Learn C unions - members that share one block of memory, how big a union is, tagged unions with an enum and switch, anonymous unions and the rules for type punning.
  5. 61 Aufzählungen (enum) Learn C enumerations - enum constants and their values, enums in switch, name tables, bit flags, sizeof, and C23 enums with a fixed underlying type.
  6. 62 Bitfelder Learn C bit-fields: struct members with a width in bits, packing flags and small values, signedness, overflow, zero-width fields and portability limits.
  7. 63 Padding und Ausrichtung Learn why C structs have holes: alignment rules, padding, offsetof, alignof and alignas, reordering members, packed structs and aligned_alloc.
  8. 64 Flexible Array Members Use a C99 flexible array member to store a header and a variable-length array in one malloc block, with correct sizing, growing, copying and the rules to avoid.

Preprocessor

  1. 65 Der Präprozessor Learn how the C preprocessor works: directives, #include with brackets or quotes, #define and #undef, #error and #warning, and gcc -E output.
  2. 66 Makros Learn C function-like macros - parentheses rules, double evaluation pitfalls, # and ##, do-while(0), variadic macros with __VA_OPT__, _Generic and X-macros.
  3. 67 Bedingte Kompilierung Learn C conditional compilation: #if, #ifdef and #elif, debug builds, include guards, #pragma once, __STDC_VERSION__, __has_include and #embed.
  4. 68 Vordefinierte Makros und assert Learn C's predefined macros - __FILE__, __LINE__, __func__, __DATE__, __STDC_VERSION__ - plus #line, runtime checks with assert and NDEBUG, and static_assert.
  5. 69 _Generic und typgenerische Makros Learn C11 _Generic generic selection - write macros that pick code by type, emulate overloading, avoid double evaluation with typeof, and use tgmath.h.

File Input and Output

  1. 70 Grundlagen der Dateiverarbeitung Learn file handling in C: FILE pointers, fopen modes (r, w, a, +, b, x), error checks with perror, fclose, fflush, and stdin, stdout and stderr.
  2. 71 Textdateien lesen und schreiben Write text files with fprintf and fputs, read them line by line with fgets, parse fields with sscanf and strtok, and count lines, words and characters in C.
  3. 72 Binärdateien Store raw bytes in C with fread and fwrite, jump around a file with fseek, ftell and rewind, save arrays of structs as records, and keep files portable across machines.
  4. 73 Fehlerbehandlung Handle errors the C way - check return values, read errno, report problems with perror and strerror, clean up with goto, and design functions that report failure clearly.
  5. 74 Dateien löschen, umbenennen und temporäre Dateien Delete and rename files with remove and rename, create temporary files safely with tmpfile and mkstemp, and avoid the classic while(!feof) bug when reading.
  6. 75 Low-Level-I/O mit Systemaufrufen Learn low-level file I/O in C with POSIX system calls - file descriptors, open flags and modes, read, write, lseek, errno, dup2 redirection, and stdio vs syscalls.

Standard Library

  1. 76 Die Math-Bibliothek Use C's math.h library - pow, sqrt, fabs, floor, ceil, round, fmod, hypot and trigonometry - link it with -lm, and detect NaN, infinity and domain errors safely.
  2. 77 Zeit und Datum Work with time in C - read the clock with time, break it into a struct tm with localtime and gmtime, format dates with strftime, do date math with mktime and time code with clock.
  3. 78 Zufallszahlen Generate random numbers in C with rand and srand, seed them properly, pick values in a range without bias, shuffle arrays with Fisher-Yates and write a better generator.
  4. 79 qsort und bsearch Sort any array in C with qsort - ints, doubles, strings and structs, with multiple keys - write correct comparator functions, and find elements fast with bsearch.
  5. 80 Nützliche Funktionen aus stdlib.h Tour the most useful functions in C's stdlib.h - exit, EXIT_SUCCESS, atexit, abort and _Exit, abs and div, getenv, and strtol and strtod for safe number parsing.
  6. 81 Befehlszeilenargumente Learn how C programs read command-line arguments with argc and argv, convert them to numbers safely, parse options like -n 5 by hand, and test it all in the editor.
  7. 82 Locales und Wide Characters Handle international text in C - set the locale with setlocale, use wchar_t and wide strings, convert UTF-8 with mbstowcs, and avoid byte-versus-character bugs.
  8. 83 Komplexe Zahlen mit complex.h Use complex numbers in C with complex.h - the double complex type, the I constant, creal, cimag, cabs, carg, cexp and csqrt, plus quadratic roots, DFT and fractals.

Data Structures in C

  1. 84 Verkettete Listen Build a singly linked list in C step by step - nodes, insertion at both ends, search, deletion with pointer-to-pointer, reversal and freeing - plus doubly linked lists.
  2. 85 Stacks und Queues Implement stacks and queues in C with arrays and linked lists, build a circular buffer queue, handle overflow and underflow, and use a stack to match brackets.
  3. 86 Binäre Suchbäume Build a binary search tree in C - insertion, search, in-order and level-order traversals, the three deletion cases, freeing the tree, and why balance matters.
  4. 87 Hashtabellen Build a hash table in C - string hash functions, separate chaining, a string-to-int map with put, get and remove, load factor and resizing, plus open addressing.
  5. 88 Sortier- und Suchalgorithmen Implement bubble, selection, insertion, merge and quick sort in C, count their work, write a correct binary search, and time every algorithm with clock().
  6. 89 Graphen und Heaps in C Build a graph with adjacency lists and a binary min-heap in C - add edges, run BFS and DFS, push and pop a priority queue, and learn the index math behind heaps.

Advanced C

  1. 90 Programme aus mehreren Dateien und Linkage Split a C program into headers and source files - what goes where, extern and static linkage, include guards, opaque types, the one-definition rule and linker errors.
  2. 91 Build-Werkzeuge: Make und CMake Automate C builds - how make decides what to rebuild, writing a real Makefile with automatic header dependencies, CMake targets and build types, and debug versus release flags.
  3. 92 Multithreading Learn multithreading in C with pthreads and C11 threads.h - create and join threads, fix race conditions with mutexes, use condition variables and atomics.
  4. 93 Signale und Signalbehandlung Learn signal handling in C - SIGINT, SIGTERM, SIGALRM and more, signal() vs sigaction, raise and kill, async-signal-safe handlers and graceful shutdown.
  5. 94 Netzwerkprogrammierung mit Sockets Learn socket programming in C - build a TCP client and server with socket, bind, listen, accept and connect, handle byte order and getaddrinfo, and use UDP.
  6. 95 Undefiniertes Verhalten Understand undefined behavior in C - what the standard means by it, why optimizers exploit it, the most common causes, and the checks and tools that keep code safe.
  7. 96 Division durch null und arithmetische Fallen Learn what happens when C divides by zero, why integers crash with SIGFPE while floats give inf and NaN, and how to check for INT_MIN / -1 and other traps.
  8. 97 C-Programme debuggen Learn to debug C programs - read compiler output and crashes, trace with fprintf and assert, step through code with GDB, and find memory bugs with Valgrind and sanitizers.
  9. 98 Modernes C: von C99 bis C23 Tour modern C from C99 to C23 - the headline features of each standard with runnable examples, how to check __STDC_VERSION__, and what today's compilers support.
  10. 99 Best Practices und typische Fehler Write safer, cleaner C - strict warnings, safe input, checking every return value, clear memory ownership, const correctness, and the beginner bugs everyone makes.
  11. 100 Prozesse: fork, exec und Pipes Create processes in C with fork, replace them with exec, collect exit codes with waitpid and connect them with pipe and dup2 - the building blocks of every Unix shell.
  12. 101 setjmp und longjmp Learn how setjmp and longjmp jump out of deeply nested C calls, build exception-like error recovery, and why leaks, volatile locals and dead frames make them risky.
  13. 102 volatile und C11-Atomics Understand what volatile really guarantees in C, why it does not make code thread safe, and how C11 atomics, compare-exchange and memory orders solve data races.
  14. 103 Memory-Mapped Files Map files into memory with mmap, edit them through pointers, use MAP_PRIVATE copy-on-write, share memory between processes with MAP_SHARED and clean up with munmap.
  15. 104 Sanitizer und Valgrind Find memory bugs and undefined behavior in C with AddressSanitizer, UBSan, LeakSanitizer and Valgrind. Learn the flags, read the reports and fix leaks.
  16. 105 E/A-Multiplexing: select, poll und epoll Handle many sockets and file descriptors in one C thread with select, poll and Linux epoll - learn fd_set, pollfd, level versus edge triggering and an epoll echo server.
  17. 106 _Static_assert und C23-Attribute Catch bugs at compile time in C with static_assert, and use C23 attributes such as nodiscard, deprecated, maybe_unused, fallthrough, noreturn and has_c_attribute.
  18. 107 Sicheres C-Programmieren Learn the C bugs behind real security holes - buffer overflows, format string attacks and integer overflow - and the habits and CERT-style rules that prevent them.
  19. 108 Fehlerbehandlung mit goto (das Cleanup-Muster) Use goto for structured cleanup in C. Learn the single-exit and cleanup-ladder patterns, compare them with nested ifs, and test every failure path.
  20. 109 C für eingebettete Systeme Learn how C talks to hardware - memory-mapped registers, volatile, bit masks, fixed-width types and interrupt handlers - with runnable simulations on a PC.

Projects

  1. 110 Projekt: Kommandozeilenrechner Build a command-line calculator in C - a tokenizer, a recursive descent parser with operator precedence, variables, math functions and clear error messages.
  2. 111 Projekt: Studentenverwaltung Build a student records manager in C - validated CSV parsing, a growable array of structs, sorting with qsort, bsearch lookups, and saving and loading files safely.
  3. 112 Projekt: Bankkontosystem Build a bank account system in C - money as integer cents, strict amount parsing, enum error codes, safe transfers, and a transaction log file you can audit.
  4. 113 Projekt: Textanalysator Build a text analyzer in C in four stages - read all input into a growing buffer, count lines and words, split words, count them in a hash table and rank the top N.
  5. 114 Projekt: Tic-Tac-Toe Build tic-tac-toe in C in four stages - a 2D array board, validated moves from the Input box, win and draw detection, and a minimax computer player with alpha-beta pruning.
  6. 115 Projekt: Lagerverwaltung mit verketteter Liste Build an inventory manager in C in four stages - a sorted linked list of items, a command interpreter, a portable binary file format, and save and load commands.
  7. 116 Projekt: Schere, Stein, Papier Build rock paper scissors in C in three stages: enums and a modular-arithmetic judge, a game loop with safe input and scores, and a computer that learns your favorite move.
  8. 117 Projekt: Galgenmännchen Build Hangman in C in two stages: game state in a struct with a guessed-letters array, then a full game with a word list, ASCII gallows, lives and input validation.
  9. 118 Projekt: Schlangen und Leitern Build Snake and Ladder in C in two stages: a jump table that stores every snake and ladder and maps squares to a zigzag grid, then a multi-player game with dice and exact-roll finish.
  10. 119 Projekt: Bibliotheksverwaltung Build a library system in C: an array of book structs with issue, return and search, then binary file persistence and a command loop that saves and reloads the shelf.
  11. 120 Projekt: Quizspiel Build a quiz game in C: load questions from a text file with careful parsing, then shuffle questions and answers, validate input and score with a speed bonus.
  12. 121 Projekt: Lexer und Klammerprüfer Build a tokenizer for a small programming language in C: keyword table, numbers, strings, operators and error tokens, then a stack-based checker for balanced brackets.
  13. 122 Projekt: 2048 im Terminal Build 2048 in C: a one-row slide-and-merge function reused for all four directions through index mapping, then a full game with random tiles, redraw and game-over detection.
  14. 123 Projekt: Einen Kalender ausgeben Print a month and a whole year calendar in C: leap-year rules, a day-of-week calculation you can verify, a month renderer that builds text lines, and a three-column year view.
  15. 124 Projekt: Reservierungssystem (Bus, Krankenhaus, Wahl) Build a bus seat reservation program in C with a seat table, booking and cancelling rules, a checksummed binary file and a command loop, then reuse the pattern for voting.
  16. 125 Projekt: Online-Wahlsystem Build a console voting system in C: register candidates with unique symbols, accept one vote per voter ID, count ballots and announce the winner or a tie.
  17. 126 Projekt: Telekom-Abrechnungssystem Build a telecom billing program in C: customer records you can add, view, modify and delete by phone number, tiered call charges in cents, and a payment ledger saved to a file.
  18. 127 Projekt: Snake-Spiel für die Konsole Build the classic Snake game in C: a grid, a snake stored as a queue of cells, walls, food, collision tests and growth, with a scripted run you can watch on the page.

Practice and Review

  1. 128 C-Spickzettel A dense one-page C reference - types, printf and scanf formats, operator precedence, control flow, functions, pointers, memory, strings, structs, the preprocessor, files and headers.
  2. 129 C-Programme: 50 klassische Beispiele 50 classic C programs with output: primes, factorial, Fibonacci, palindromes, GCD and LCM, Armstrong numbers, base conversion, strings, sorting and matrices.
  3. 130 C-Programme zum Ausgeben von Mustern Pattern printing programs in C with output: hollow and inverted pyramids, diamonds, number and letter triangles and reverse Floyd's triangle, with the loop logic explained.
  4. 131 Weitere C-Programme zu Zeichenketten More string programs in C with output: add binary strings, first non-repeating character, pangram check, word initials, strip leading zeros, insert, split and compare.
  5. 132 Zeigerprogramme in C: 7 klassische Beispiele Seven C pointer programs with output: functions that return pointers, jagged 2D arrays, pointer-only sorting, sorting strings, pointer palindromes, recursive list copy and stack reversal.
  6. 133 Ungewöhnliche C-Programme: Quine, Fehlerarten, unerreichbarer Code Write a C program that prints its own source, see compile, link, runtime and logic errors side by side, learn why GCC stays quiet about unreachable code, and print a name's initials.
  7. 134 C-Übungsaufgaben 30 graded C exercises with solutions on loops, functions, arrays, strings, pointers, malloc, structs, linked lists, bit flags and files. Run C in your browser.
  8. 135 C-Interviewfragen 50 common C interview questions with clear answers, from pointers, arrays and strings to malloc, structs, padding, macros, undefined behavior and threads.