CPU, memory, storage, and the operating system
Build a practical model of the parts involved when an ordinary computer runs a program, without mistaking that model for C’s rules.
In this chapter9 sections
When you open an application, several parts of your computer work together. Let us separate the jobs of the processor, working memory, storage, and operating system. We will use a typical laptop as our example; other C environments can be different.
1. The processor carries out machine operations
The CPU is the central processing unit. It executes machine instructions for tasks such as arithmetic, comparison, and moving data. Small storage locations called registers hold information it is working with. Devices and other components can also do work, so the CPU is one part of the system.
The CPU does not inherently recognize a C variable name such as apples. A language implementation connects source-level concepts to operations supported by the target system. Source names may help debugging tools, but the language does not require every named object to occupy its own permanently visible physical location.
2. Working memory supports active computation
On a typical laptop, RAM supplies much of the working storage used by running programs. Ordinary RAM loses its contents when power is lost. The processor also uses registers and caches, so every operation need not read directly from RAM.
An address identifies a location in an address space. Common operating systems use virtual addresses and map them to resources. For now, use the idea of a location without imagining a universal physical RAM coordinate. Later we will add C’s rules for pointer types, valid targets, and lifetimes.
3. Persistent storage keeps files between sessions
An SSD or hard drive commonly stores files after an application closes. These can include source code, executable programs, and saved documents. To run a program, the system makes the needed code and data available. It does not necessarily copy every related file into RAM at once.
This distinction explains why saving matters. Editing a document changes the application’s current state; writing a file requests persistence outside that working state. The details of buffering, failures, and durable storage require further care. For now, “it is currently visible on screen” and “it has been saved successfully” should not be treated as the same fact.
| Part | Useful first question |
|---|---|
| CPU and registers | Which operations are being executed, and on what immediate information? |
| Working memory | What information is currently available to the running program? |
| Persistent storage | What has been stored as a file or other persistent record? |
| Operating system | Who coordinates resources, permissions, devices, and processes? |
4. The operating system coordinates access
The operating system manages facilities such as processes, memory, files, and devices. Applications request services through interfaces, often using libraries. A C output call may pass through several layers before text appears. It does not directly command the display electronics.
The OS also participates in isolation and permissions. Knowing C does not automatically grant permission to read another process’s memory or access every device. A language feature and a system privilege are different things. Programs can fail because a file is missing, access is denied, or a resource is exhausted, even when the relevant C syntax is correct.
5. A program file and a process are different
A program file stores code and related information. A process, on common systems, is a running instance with its own execution state and resources. Two instances can have different current values. Changing a value in a running instance does not automatically rewrite the program file.
The desk analogy can help: storage is like a filing cabinet and working memory like materials currently on a desk. Its limits are important. Information is encoded rather than moved as a physical sheet; mappings, caches, shared resources, and optimizations do not behave like one literal desk. Keep the roles, not every physical detail of the picture.
6. C does not require a desktop operating system
C distinguishes hosted and freestanding execution environments. In a hosted environment, the language specifies familiar startup forms involving main and the full hosted library requirements. Freestanding implementations, used in settings such as firmware, have different startup and library provisions. Do not turn a diagram of a laptop into a requirement for every C implementation.
You change a counter in a running application and close it without a successful save operation. Must the executable file now contain that counter value?
Read the explanation
No. Execution state and a stored program file have different roles. Persistence needs an appropriate successful operation; changing a working value does not itself rewrite the executable.
Primary references and further reading
- WG14 N1570 — public C11 committee draft: Sections 5.1.2 and 6.2.4 distinguish execution environments and object lifetimes; the laptop model above is explanatory context, not a C-mandated machine layout.
- Linux kernel documentation — memory management concepts: A concrete operating-system example of virtual memory concepts; its details are not portable C guarantees.
Before you move on
- The processor, working memory, storage, and operating system have different roles.
- A running process has state that differs from the stored executable file.
- Saving data requires a suitable successful operation beyond changing a working value.
Keep these ideas separate
- Working memory / Persistent storage
- Working data can disappear when a program ends; persistence depends on the storage and successful save policy.
Why can two running copies of the same program show different current values?
Optional: say it aloud or keep a note. You can continue whenever you are ready.Check your understanding
Optional. Answers are not saved or sent, and reading stays unrestricted.
Read the explanation for every choice
- RAM and persistent storage are interchangeable.
Working memory and persistent storage have different roles and persistence properties.
- Working memory and persistent storage serve different roles.
✓ Correct reasoning. Saving normally writes data to persistent storage; keeping a value in working memory is a different operation.
- A CPU permanently saves every intermediate value.
Executing operations does not automatically create a persistent copy of every value.
General
Ready for the next idea?
Mark this chapter as read whenever you feel ready.