C Tutorial
C is one of the most important programming languages ever made. It was created in the early 1970s to write the Unix operating system, and today it still runs inside operating systems, phones, cars, washing machines and the programs that run other programs. Learning C teaches you how a computer really works: memory, addresses, bytes and the cost of every instruction.
This tutorial takes you from your very first program to pointers, structures, dynamic memory and files. Each topic explains one idea in plain words and shows short example programs. Every example has a Try it in the editor button: it opens the program in our online C compiler in a new tab, where you can change it, run it and see what happens. Nothing needs to be installed.
How this tutorial is organised
The topics follow the order most courses use, and each one builds on the ones before it.
- Basics: the shape of a program, output, variables, data types, operators, decisions, loops, arrays, strings, user input and pointers.
- Functions: writing your own functions, parameters, scope and recursion.
- Structures and memory: structures, enums, unions and memory you allocate while the program runs.
- Files and larger programs: reading and writing files, the preprocessor, header files and splitting a program into several files.
Use the topic list to jump anywhere, and the Previous and Next links at the end of each page to read the course in order.
Your first look at C
Here is a complete C program. Press Try it in the editor, then Run, and the terminal shows its output.
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}Hello, World!
Every C program you write in this tutorial has the same shape: a few #include lines at the top, and a main function where the program starts. The next topic, Get Started, explains each line.
Tips for learning C
- Type the examples yourself. Reading code is not the same as writing it. Small typing mistakes teach you to read the compiler's messages.
- Change things and run again. Change a number, remove a semicolon, print one more line. Predict what will happen first, then check.
- Read the error messages. The compiler tells you the file, the line and what it expected. Our editor also adds a hint in plain words.
- Use Safe mode. In the editor's Options, Safe mode stops a program that uses an array index outside the array or forgets to free memory, and tells you where.
Practice exercises
- Run the example above, then change the text so it prints your own name.
- Add a second
printfline that prints the name of your city. - Remove the semicolon after the
printfline, run the program and read the error and the hint. Put the semicolon back.