Loading lessons...
How Computers Understand Programs
How Computers Understand Programs
Before we write code, let's peek at what actually happens inside a computer.
What is a program?
A program is a set of instructions that tell the computer what to do. The computer runs the instructions one after another, and together they do something useful.
Machine code: the CPU's only language
The computer's processor (CPU) understands exactly one language: machine code - patterns of 1s and 0s called bits.
- Machines read bits, not English.
- Machine code is fast to run but painful for people to read.
High-level vs. low-level languages
- High-level (like C++): uses words and structure that resemble how people think. Readable and easy.
- Low-level (like assembly or closer to the machine): harder to read, but gives you tight control.
| Kind | Example | Good for |
|---|---|---|
| High-level | C++ | readable programs people can maintain |
| Low-level | Machine code | running directly on the CPU |
Source code
The code you type in an editor is called source code. It's the human-readable version of a program. The compiler later turns it into something a machine can run.
Why do we need programming languages?
Humans and computers speak very different tongues. A programming language is the bridge between the two: we write friendly words, and the compiler translates them into bits the CPU understands.
TL;DR
- A program is a list of instructions run in order.
- The CPU only understands machine code (1s and 0s).
- High-level languages are easy for humans; low-level ones sit close to the machine.
- You write source code; the compiler turns it into executable instructions.