Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction to C  ›  Lesson

Where C Runs

Applications 10 minC is chosen where software must control memory and hardware closely, run fast without a runtime, and be callable from many other languages.

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:

  1. Is memory or processing power tight?
  2. Must the code talk to hardware or the operating system directly?
  3. Must many other languages be able to call it?
Should the greenhouse project use C?Step 1 of 3
  1. 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.

quick drill

Which of these is written mainly in C?

quick drill

A thermostat chip has 16 KB of memory and must read a sensor register. Which shortcut questions get a "yes"?

quick drill

Why can Python, Rust and Go all use a library written in C?

quick drill

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.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainIs C still worth it?

A friend says C is outdated and nobody needs it any more. Using the greenhouse logger and one other real example, explain where C is still the best choice and name one real cost of choosing it.