Where C Runs
The radio chip in your phone, the kernel of the server that sent you this page, and the Python interpreter many people learn first have something in common: large parts of them are written in C. A language designed in the early 1970s is still the default wherever software sits close to the machine. In this course you will grow one small program, a logger for a greenhouse sensor board, and it is exactly the kind of job C was made for.
The rule
Reach for C when every byte, cycle and wire matters.
C gives you three things that few languages give together:
- Control of memory. You decide how big each value is and where it lives. No garbage collector moves things behind your back.
- Predictable speed. C compiles straight to machine code. There is no interpreter or virtual machine between your program and the processor.
- A universal interface. Almost every language can call a C function, so C is the glue between systems.
That combination explains where C shows up:
| Area | Examples |
|---|---|
| Operating systems | The Linux kernel, large parts of Windows and macOS internals |
| Embedded devices | Thermostats, car sensors, washing machines, our greenhouse board |
| Language runtimes | CPython, the standard Ruby interpreter, Lua |
| Databases | SQLite, PostgreSQL, Redis |
| Networking and tools | The nginx web server, the curl command-line tool |
Here is the first line our logger will ever have. It is tiny, and on the board it costs only a few bytes of memory:
int reading_count = 0; /* how many temperatures we have logged */The shortcut
Ask three questions about a project. A "yes" to any of them makes C a strong candidate:
- Is memory or processing power tight?
- Must the code talk to hardware or the operating system directly?
- Must many other languages be able to call it?
The sensor board
Its chip has 32 KB of RAM (question 1: yes) and reads the temperature sensor through a hardware register (question 2: yes). C is a natural fit.
The trap is thinking "C is fast, so use it everywhere". Its control has a price: you manage memory yourself, and mistakes such as writing past the end of an array are not caught for you. For a script you run once, that trade is rarely worth it.
Drills
Answer fast — trust the rule.
Which of these is written mainly in C?
A thermostat chip has 16 KB of memory and must read a sensor register. Which shortcut questions get a "yes"?
Why can Python, Rust and Go all use a library written in C?
Which job is the weakest fit for C?
Remember
- Reach for C when every byte, cycle and wire matters: tight memory, direct hardware, or code many languages must call.
- Shortcut: ask the three questions; any "yes" makes C a strong candidate.
- Trap: C's control costs you safety nets, so it is a poor choice for quick one-off jobs.
