Course contentsShow
← C
Lesson 447 of 1,2197. PointersFree lesson

Memory as a linear sequence of bytes

Memory as a linear sequence of bytes

What you'll learn: Understand how your computer’s RAM is structured as a simple, numbered row of storage units.

The Long Row of Cubbies

Imagine a massive post office containing millions of tiny mail slots, or "cubbies," arranged in a single, straight line. Each cubby is exactly the same size: one byte (8 bits).

In C, we often think of variables as names like age or price. However, the computer sees them as specific locations in this long, linear sequence. Because every cubby is the same size, we can give each one a unique number to identify it. This number is called a memory address.

Linear and Sequential

When we say memory is "linear," we mean it flows in one direction. The first byte is at address 0, the next is at 1, the next at 2, and so on, up into the billions.

When you declare a variable, the computer sets aside a chunk of these cubbies. A small piece of data, like a char, might only need one cubby. A larger piece of data, like an int, usually needs four cubbies in a row.

#include <stdio.h>

int main() {
    // A single character occupies 1 byte at one address
    char letter = 'A';
    
    // An integer occupies 4 bytes at four consecutive addresses
    int number = 100;

    // We use %p to print the 'address' or the 'location' 
    // of these variables in the sequence.
    printf("The letter is stored at address: %p\n", (void*)&letter);
    printf("The number starts at address: %p\n", (void*)&number);

    return 0;
}

Why Addresses Matter

Pointers are simply variables that store these address numbers. If you know the address of the first cubby in a sequence, you know exactly where that data begins.

Even though we visualize our code as having different sections and functions, everything eventually boils down to this simple, flat row of bytes. Whether it’s a photo, a line of text, or a number, it all sits somewhere in that long, numbered line of memory.

Key takeaway

Computer memory is a giant, numbered list of one-byte slots where every piece of data has a specific numerical address.