Introduction to C
C is a programming language created by Dennis Ritchie at Bell Labs in the early 1970s to build the Unix operating system. It is small, fast and close to how the computer actually works, and it's still everywhere: operating systems (Linux, Windows' core), databases, embedded devices, game engines, and the interpreters of other languages, including Python itself.
Why learn C?
- You learn how computers really work: memory, addresses, how data is laid out.
- Speed: C programs run very close to the speed of the hardware.
- Foundations: C++, Java, C#, JavaScript and many others borrow C's syntax, so C makes them easier to learn.
Software you use every day is written in C:
| Program | What it is |
|---|---|
| the kernel under Android, most web servers and nearly every supercomputer | |
| the standard Python interpreter | |
| the database inside phones, browsers and countless apps | |
| the version control nearly every developer uses | |
| a very fast in-memory database |
A first look
#include <stdio.h>
int main() {
printf("Hello, C!\n");
return 0;
}Press Run. Every line has a job, which the next lesson takes apart piece by piece.
Compiled, not interpreted
C is a compiled language. Before a C program can run, a compiler (such as GCC or Clang) translates the whole source file into machine code, producing an executable file:
gcc hello.c -o hello # compile
./hello # run the resultThe compiler checks the whole program first, so many mistakes are caught before the program ever runs.