Explain it simply
Explain it simply
C is a small programming language that sits very close to the hardware. You write instructions as plain text in a .c file, and a program called a compiler translates that whole file into machine code, the raw instructions your processor executes. Nothing has to translate your program while it runs, which is a big reason C programs start fast and use little memory.
The price of that speed is responsibility. C trusts you to stay inside the memory you asked for, to give every value the right type, and to clean up after yourself. Think of it as a manual-transmission car: you get precise control, and the car does not stop you from shifting into the wrong gear.
Problem → Why → Solution
The problem: C trusts you, even when you are wrong
Here is a program a beginner might write. The array holds three scores, but the code asks for the sixth one. Languages like Python or Java stop at this line with an index error. C compiles it, runs it, and prints whatever bits happen to sit in that memory. On one test run with GCC it printed -1555296038, and even with -Wall -Wextra switched on there was no warning.
Only after adding -O2 (optimization) did GCC report "array subscript 5 is above array bounds of 'int[3]'". That difference is the first lesson of this course: in C, the tools help only as much as you ask them to.
#include <stdio.h>
int main(void) {
int scores[3] = {90, 75, 88};
printf("%d\n", scores[5]); /* index 5 does not exist */
return 0;
}Why does C allow this?
C was designed in the early 1970s to write the Unix operating system, when every instruction counted. Checking each array access at runtime costs time, so the language leaves that job to the programmer. The C standard calls code like this undefined behavior: the program is broken, but nothing is required to tell you. That is why every lesson here compiles with warnings switched on and treats one correct-looking output as a hint, not a proof.
Core concept: from a text file to a running program
C is a compiled, statically typed language. Compiled means the translation happens once, before the program runs. Statically typed means every variable has a type the compiler knows, such as int for whole numbers or double for decimals. Because the compiler knows the types, it can turn your code into compact machine instructions and catch many mistakes before you run anything. C is also procedural: a program is a set of functions, and execution always begins in the one named main.
1. Preprocess
Lines that start with # are handled first. #include <stdio.h> pastes in the declarations of the standard input/output functions, such as printf.
2. Compile
The compiler checks your syntax and types, then translates each .c file into an object file of machine code. Syntax errors and most warnings come from this stage.
3. Link
The linker joins your object files with the C standard library, which holds the real code of printf. A missing function shows up here as an "undefined reference" error.
4. Run
The operating system loads the executable and calls main(). When main returns 0, the program tells the system it finished successfully.
The C build pipeline
--------------------
hello.c --> [preprocessor] --> [compiler] --> hello.o
|
C standard library (printf, ...) --> [linker] <---+
|
v
hello (hello.exe) --> run main()C is also a standard, not a single product. ISO publishes the rules, and compilers such as GCC, Clang and Microsoft's MSVC implement them. Major revisions are known by year: C89/C90, C99, C11, C17 and C23. This course teaches portable C17, which current versions of the major compilers accept, and points out the few places where C23 changes something you will type.
You will meet these stages again and again. Error messages look different depending on which stage complained, and knowing the stage tells you where to look.
- You write source text in hello.c
- Preprocessor pastes in headers
- Compiler produces machine code
- Linker adds library, OS runs it
When something breaks, first ask which stop complained: compiler errors point at a line, linker errors name a missing function.
General pattern: the smallest C program
#include <header.h> /* bring in declarations you need */
int main(void) { /* the program starts here */
statement; /* each statement ends with ; */
statement;
return 0; /* 0 tells the OS: success */
}Every program in this course grows from this shape: a few #include lines, then main, whose body is a list of statements run from top to bottom. return 0 hands a success status back to the operating system.
Example: your first program
This program prints a greeting and the size of the course. The lesson count is not typed in as text: the program adds the five chapter sizes itself, so you can see C doing real work. Predict the output before you compile and run it.
#include <stdio.h>
int main(void) {
printf("Welcome to C!\n");
printf("Chapters: Basic, Intermediate, Advanced, Projects, Exercises\n");
printf("Lessons: %d\n", 15 + 7 + 8 + 2 + 2);
return 0;
}Code breakdown
- Line 1
#include <stdio.h>Asks the preprocessor to paste in stdio.h, the header that declares printf. Without it, recent GCC versions refuse to compile the call.
- Line 3
int main(void) {Defines main, the function the operating system calls first. int is the type of the status it returns, and void says it takes no arguments.
- Line 4
printf("Welcome to C!\n");Prints text. The \n at the end is the escape sequence for a newline, so the next output starts on a fresh line. The semicolon ends the statement.
- Line 6
printf("Lessons: %d\n", 15 + 7 + 8 + 2 + 2);%d is a placeholder for an int. printf replaces it with the value of the next argument, the sum 34. The Output lesson covers these placeholders in detail.
- Line 7
return 0;Ends main and reports success. A non-zero value would tell the shell, or a script that ran the program, that something went wrong.
Welcome to C!
Chapters: Basic, Intermediate, Advanced, Projects, Exercises
Lessons: 34How this course is organized
| Chapter | Lessons | What you learn |
|---|---|---|
| Basic | 1-15 | Program structure, output, comments, variables, data types, constants, operators, booleans, if/else, switch and loops |
| Intermediate | 16-22 | Arrays, strings, functions and their parameters, declarations, recursion and the math library |
| Advanced | 23-30 | User input, file I/O, memory addresses, pointers, dynamic memory, structures, unions and enums |
| Projects | 31-32 | A mini project that combines the earlier lessons, plus a course summary |
| Exercises | 33-34 | Practice sets on the fundamentals and on functions with pointers |
Each lesson follows the same path: a plain-language explanation, a real problem, the core concept, a worked example you can run, common mistakes, a mini challenge and a short quiz. The challenge starter is a skeleton on purpose, because typing the code yourself is how the syntax sticks.
How to study each lesson
1. Predict first
Before you run a program, write down what you think it prints. A wrong guess shows you exactly what to reread.
2. Type, do not paste
Typing builds the habit of the semicolons, braces and quotes that C insists on.
3. Break it on purpose
Delete a semicolon or misspell printf and read the message. Errors you have caused deliberately are far less scary later.
4. Keep warnings on
When you compile on your own machine, use gcc -std=c17 -Wall -Wextra. The next lesson shows how.
In real projects
Where C runs today
C is everywhere, mostly out of sight. The Linux kernel, which runs most web servers and every Android phone, is written mainly in C. So are SQLite, the database built into phones and web browsers, and CPython, the program that runs Python code. When you call a fast library from Python, there is often C underneath.
C also dominates small devices. Microcontrollers in washing machines, car engine units, routers and medical sensors often have only kilobytes of memory and no operating system, and C fits there because it adds almost nothing on top of your own code. Finally, C acts as a common language between other languages: Rust, Go, Python and many more can call functions that follow C's calling conventions, so libraries written in C are reused everywhere.
Common mistakes
Common mistakes when starting C
1. Treating a correct output as proof
The array example above printed a number and exited normally, yet it read memory it did not own. In C, a program with undefined behavior can pass a quick test today and fail on another compiler, another optimization level or another machine. Check the code, not just the output.
2. Compiling with warnings off
Many C mistakes are legal syntax, so the compiler only mentions them as warnings, and only when asked. A beginner who compiles with a bare gcc file.c misses messages that would have pointed straight at the bug. Make -Wall -Wextra part of every build and treat each warning as a question you must answer.
3. Expecting Python or JavaScript habits to carry over
C has no built-in string type, no automatic bounds checks and no garbage collector. Text is an array of characters, and memory you request yourself must be released by you. Read the Strings and Dynamic Memory lessons slowly, even if you already program in another language.
Best practices
Best practices
- Compile the examples on your own machine, not only in an online editor, so the toolchain stops being a mystery.
- Keep a small notes file of every error message you met and what fixed it.
- Finish the Basic chapter before jumping to pointers, because pointers build on types, operators and arrays.
Mini challenge
Mini challenge: your study card
Write a program that prints a small study card for this course. It should look tidy in the terminal and let C compute one number for you.
- Print a title line such as === My C study card ===
- Print the total lesson count with %d, computed from the chapter sizes 15, 7, 8, 2 and 2
- Print how many lessons you plan to finish each week
- End every line with \n and return 0 from main
#include <stdio.h>
int main(void) {
// TODO: print a title line for your card
// TODO: print "Lessons to finish: " followed by the sum of the
// chapter sizes (15, 7, 8, 2, 2) using %d
// TODO: print your weekly goal, e.g. "Lessons per week: 4"
return 0;
}Expected: Your program prints four lines like these (your weekly goal may differ): === My C study card === Lessons to finish: 34 Lessons per week: 4 First stop: Get Started
Show hint
printf("Total: %d\n", 1 + 2); prints Total: 3. Put the addition after the comma and keep the %d inside the quotes.
Show solution
#include <stdio.h>
int main(void) {
printf("=== My C study card ===\n");
printf("Lessons to finish: %d\n", 15 + 7 + 8 + 2 + 2);
printf("Lessons per week: %d\n", 4);
printf("First stop: Get Started\n");
return 0;
}Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- C is a compiled, statically typed language that runs close to the hardware, which is why it powers kernels, databases and small devices.
- A program passes through preprocessing, compiling and linking before the operating system calls main().
- C trusts the programmer: out-of-bounds reads and similar mistakes are undefined behavior, not guaranteed errors.
- Compile with warnings on and treat one correct output as a hint, not proof.
- The course has 34 lessons in five chapters: Basic, Intermediate, Advanced, Projects and Exercises.
ISO C Working Group (WG14) — ISO/IEC JTC1/SC22/WG14