To learn C, work through it in layers: syntax and control flow first, then functions, arrays and strings, then pointers, then dynamic memory, building a small program at each stage. Compile with warnings on from the first day and add a memory checker once you reach pointers.
C rewards a particular order. Each topic leans on the one before it, and the topics that trip people up (pointers, strings, malloc) are the ones that come late. Skipping ahead to pointers before you are comfortable with arrays and functions is the most common reason people stall. This roadmap lists the stages, what "done" looks like for each, and what to build.
Stage 0: set up a compiler and a feedback loop
You need a text editor, a compiler (GCC, Clang or MSVC) and a terminal. The step-by-step setup, including the Windows developer prompt for MSVC, is in how to code in C: your first program, compile and run. Two habits to set now:
- Compile often. After every few lines, not after a whole file. The error you get then points at the few lines you just wrote.
- Turn on warnings. With GCC or Clang:
gcc -Wall -Wextra -g prog.c -o prog. The-gflag, per the GCC documentation, produces debugging information that GDB can use. Treat every warning as a bug to fix.
Done when: you can edit a file, compile it, run it, and read the first error message the compiler prints.
Stage 1: types, operators and control flow
Learn the core pieces: int, char, double, the arithmetic and comparison operators, if/else, switch, and the for and while loops. Learn printf with its format specifiers early, because it is your main way to see what your program is doing.
Two C-specific points belong in this stage. A local variable you do not initialise holds an indeterminate value, so always give it one. And integer division truncates: 7 / 2 is 3, not 3.5.
Build:
- A temperature converter that prints a table from 0 to 100 in steps of 10.
- FizzBuzz.
- A program that prints the first 20 Fibonacci numbers.
Done when: you can write each of these without looking anything up except a format specifier.
Stage 2: functions
Split programs into functions with clear inputs and one job each. Learn declarations versus definitions, why a function should be declared before it is called, and that C passes arguments by value: a function receives a copy, so changing a parameter does not change the caller's variable. That fact is the reason pointers exist in the next stage, so make sure it is solid.
Build: rewrite your Stage 1 programs so that main only calls functions such as is_prime(int n) or fib(int n).
Done when: you can explain, without code, why void swap(int a, int b) does not swap anything in the caller.
Stage 3: arrays and strings
An array is a fixed-size block of elements of one type. Two rules matter most. First, the size is not stored with the array. According to cppreference, an array used in most expressions is converted to a pointer to its first element, and an array parameter is adjusted to a pointer, so the callee cannot learn the array's length. You pass the length as a separate argument. Second, sizeof is one of the exceptions to that conversion, which is why sizeof on an array in the same scope gives the full size in bytes but gives only the pointer size inside a function that received it.
A C string is an array of char that ends with a zero byte. There is no string type, so copying, comparing and joining all need library functions and a buffer big enough for the result including the terminator. Read arrays in C and strings in C: char arrays and the null terminator before you write anything that reads user input.
Build:
- Find the largest value and the average of an array of numbers.
- Reverse a string in place.
- Count the words in a line of text.
Done when: you always know how big every buffer is and can say where the terminating zero byte goes.
Stage 4: pointers
A pointer holds the address of another object. This is the stage most learners find hardest, and the cure is small experiments, not more reading. Print an address with %p, dereference it, change a variable through a pointer parameter, then walk an array with a pointer. Then fix your Stage 2 swap using pointers.
Work through pointers in C explained with examples with a compiler open, and type the examples instead of pasting them. Pay attention to the link back to Stage 3: arr[i] and pointer arithmetic over the first element are two views of the same thing.
Build: a function that returns both the minimum and the maximum of an array by writing them through two pointer parameters, and a function that splits a string at the first space.
Done when: you can read a declaration such as char *argv[] aloud and say what each part means.
Stage 5: structs and dynamic memory
A struct groups related values into one type. With malloc and free, you can create data whose size is only known at run time. Each malloc needs exactly one matching free, and the result of malloc can be NULL, so check it. The details are in malloc in C: allocate, free and avoid leaks.
Build, in this order:
- A dynamic array that grows when it is full.
- A singly linked list with insert, delete and print.
- A small command-line contact book that stores structs and saves them to a file.
Done when: your program frees everything it allocates and you can show that with a tool, not just by reading the code.
Add a memory checker once you use pointers
From Stage 4 onward, compile with sanitizers. GCC's documentation describes -fsanitize=address as a fast memory error detector that finds out-of-bounds and use-after-free bugs, and says to use -g with it for more meaningful output. -fsanitize=undefined is described as a fast undefined behavior detector. Both can be combined:
gcc -Wall -Wextra -g -fsanitize=address,undefined prog.c -o prog
./prog
Clang accepts the same options. A program that reads past the end of an array then stops with a report naming the file and line instead of printing wrong results. Sanitizer availability varies by platform and toolchain, so if the flag is rejected on your setup, check your compiler's documentation. The debugger is the second tool: build with -g and step through with GDB or your editor's debugger.
Which C standard to learn
C has had several revisions. According to cppreference's history page, C99 added bool, long long, <stdint.h>, // comments and declarations mixed with statements. C11 added threads and atomics support and removed gets. C17 is a defect-fix revision with no major new features, and C23 is the current one. For learning, use whatever your compiler defaults to and do not spend time on the differences. Do avoid any tutorial that still uses gets.
How to practise without stalling
- Type code, do not paste it. The typing is where you notice the syntax.
- Predict before you run. Write down what the program will print. A wrong prediction marks exactly what you misunderstand.
- Change one thing at a time. If a program breaks, undo the last change before trying anything else.
- Read the first error only. Later errors are often side effects of the first.
- Finish small programs. A 40-line program that works and that you understand teaches more than a 400-line one you copied.
If you are stuck
If a stage feels impossible, the cause is usually the stage before it. Trouble with pointers is often shaky understanding of pass-by-value (Stage 2) or of arrays (Stage 3). Go back, write one tiny program that isolates the gap, and return. If your program crashes and you cannot see why, rebuild it with the sanitizer flags above and read the first line of the report.
Frequently asked questions
- How long does it take to learn C?
- There is no reliable figure, because it depends on prior programming experience and weekly hours. A practical marker is milestones rather than months: you can write small programs with functions and arrays, you understand pointers well enough to explain what a pointer parameter does, and you can allocate and free memory without leaks. Reaching those milestones is a better test than a calendar.
- Should I learn C or C++ first?
- They are separate languages that share syntax. Learning C first keeps the scope small: no classes, templates or large standard library, so you spend your time on memory and pointers. If your goal is C++ specifically, going straight to C++ is also reasonable. Pick the language your target projects use.
- Is C still worth learning?
- It is still used for operating system kernels, embedded firmware and language runtimes, and the ISO standard keeps being revised: C23 is the current revision according to cppreference. Even if you never write C professionally, it teaches how memory, arrays and strings work underneath higher-level languages.
- Which C standard should a beginner learn?
- Learn modern C and use your compiler's default. The differences between C99, C11 and C17 are small for beginner material, and C17 is described by cppreference as a defect-fix revision with no major new features. Avoid very old tutorials that teach C89 habits such as declaring every variable at the top of a function or using gets.